Results 1 to 5 of 5

Thread: Cannot reference my spring config files from another project

  1. #1

    Default Cannot reference my spring config files from another project

    Hello,

    I have 2 projects. Both with "Spring Project Nature". In the second project I want to use beans from the first project. Therefore I've added the first project under the Project References and created a config set that holds the spring config file from the first project. I can see that config set in the second projcet under properties. So I thought everything would be alright. But it is not.
    Is there anything more I have to add e.g. in my web.xml file? So far my web.xml file looks like this:

    ....

    <listener>
    <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
    </listener>
    <servlet>
    <servlet-name>ldm</servlet-name>
    <servlet-class>
    org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/xml/ldm-servlet.xml</param-value>
    </init-param>

    <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>ldm</servlet-name>
    <url-pattern>*.htm</url-pattern>
    </servlet-mapping>


    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
    /WEB-INF/xml/common-data1.xml
    </param-value>
    </context-param>

    <context-param>
    <param-name>javax.servlet.jsp.jstl.fmt.localizationContex t</param-name>
    <param-value> config/internationalstrings
    </param-value>
    </context-param>
    ....

    The referencened common-data1.xml looks like this:
    ...
    <beans>
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.Hibernat eTransactionManager">
    <property name="sessionFactory"><ref bean="sessionFactory"/></property>
    </bean>
    <!-- sessionFactory and every other bean used in that project are configured in the springConfig.xml of the first project -->
    </beans>
    ..

    While deploying on JBOSS 3.2.6 there is an exception thrown caused by the entry "sessionFactory" in common-data1.xml. Because this bean couldn't be found. Although it is configured in the springConfig.xml file of the first project.
    What is wrong here?

    What, if I only want to use the springConfig.xml file from the first project, without any extra bean configuration in that
    second project? I deleted the section "contextConfigLocation" in my web.xml and was hoping, that now only the referenced file from the config set would be taken. But this was not the
    case! While deploying, a config file named "/WEB-INF/applicationContext.xml" had to be loaded. But of course I don't have such a file, because I wanna use my springConfig.xml from the first project. That caused an exception again. What can I do?

    Thank you for your support
    Lori

  2. #2
    Join Date
    Aug 2004
    Location
    Frankfurt/Main, Germany
    Posts
    253

    Default Re: Cannot reference my spring config files from another pro

    Quote Originally Posted by lorelia
    I have 2 projects. Both with "Spring Project Nature". In the second project I want to use beans from the first project. Therefore I've added the first project under the Project References and created a config set that holds the spring config file from the first project. I can see that config set in the second projcet under properties. So I thought everything would be alright.
    From Spring IDE's perspective everything is perfect. The BeansConfigValidator is able check your BeansConfigSet which contains BeansConfig files from separate Eclipse projects.

    Here ends the responsibility of Spring IDE (which is only about visializing and validating Spring beans config files and not about runtime stuff, e.g. deployment).

    Quote Originally Posted by lorelia
    But it is not.
    Is there anything more I have to add e.g. in my web.xml file?
    No, for Spring IDE you're fine.

    Quote Originally Posted by lorelia
    While deploying on JBOSS 3.2.6 there is an exception thrown caused by the entry "sessionFactory" in common-data1.xml. Because this bean couldn't be found. Although it is configured in the springConfig.xml file of the first project.
    What is wrong here?
    Your webapps are loaded into different classloaders. So one webapp can't access the classpath resource of another webapp. This is what the servlet spec is demanding.

    Quote Originally Posted by lorelia
    What, if I only want to use the springConfig.xml file from the first project, without any extra bean configuration in that
    second project? I deleted the section "contextConfigLocation" in my web.xml and was hoping, that now only the referenced file from the config set would be taken. But this was not the
    case! While deploying, a config file named "/WEB-INF/applicationContext.xml" had to be loaded. But of course I don't have such a file, because I wanna use my springConfig.xml from the first project. That caused an exception again. What can I do?
    Maybe you ask this question in the web-specific forum again.

    Cheers,
    Torsten

  3. #3

    Default So what's the benefit then?

    Hey Torsten,

    thank you very much for your quick reply. If everything is set up right and does not do the thing i've expected it to do, what is the benefit of Spring IDE in case of referencing other projects? Why should I add config files to an other project if I cannot use the beans from that config file in that other project? I just don't get it ;-). Can you help me out? I thought by doing so, I could better separate business and database logic from web layer. That was my plan. I have a project only for business and database classes and I have another one only for web purposes, which then references the first project with the business and database classes and uses the beans (configured in the config file) from this project to.

    Thanks
    Lori

  4. #4
    Join Date
    Aug 2004
    Location
    Frankfurt/Main, Germany
    Posts
    253

    Default Re: So what's the benefit then?

    Quote Originally Posted by lorelia
    If everything is set up right and does not do the thing i've expected it to do, what is the benefit of Spring IDE in case of referencing other projects?
    Spring IDE is only about validating and visualizing Spring bean config files. And Spring bean config files spread accross different Eclipse projects are supported too. So nothing more and nothing less is the scope of Spring IDE.

    Quote Originally Posted by lorelia
    Why should I add config files to an other project if I cannot use the beans from that config file in that other project? I just don't get it ;-). Can you help me out?
    I didn't say it's not possible. I did recommend asking your question in one of the more Spring-related forums because my hometurf is Spring IDE not Spring in general.

    Cheers,
    Torsten

  5. #5

    Default Things are clear now!

    Hey Torsten,

    thanks again. I had the wrong picture about Spring IDE. Thank you for clearing it.

    Lori

Similar Threads

  1. Replies: 3
    Last Post: Jun 22nd, 2010, 08:15 PM
  2. Gaijin Studio for Spring MVC 0.9.2 Released
    By dadams in forum Announcements
    Replies: 8
    Last Post: May 30th, 2007, 10:48 PM
  3. Managing large Spring XML config files
    By roshang in forum Architecture
    Replies: 7
    Last Post: Oct 12th, 2005, 10:16 AM
  4. Unexpected behaviour with multiple config files
    By rgitzel in forum Container
    Replies: 7
    Last Post: Mar 8th, 2005, 07:11 PM
  5. Replies: 14
    Last Post: Feb 21st, 2005, 05:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •