Announcement Announcement Module
Collapse
No announcement yet.
Cannot reference my spring config files from another project Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    Re: Cannot reference my spring config files from another pro

    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).

    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.

    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.

    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

    Comment


    • #3
      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

      Comment


      • #4
        Re: So what's the benefit then?

        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.

        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

        Comment


        • #5
          Things are clear now!

          Hey Torsten,

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

          Lori

          Comment

          Working...
          X