PDA

View Full Version : Cannot reference my spring config files from another project


lorelia
Aug 28th, 2005, 09:48 AM
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.ContextLoaderListe ner</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.localizationContext</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.HibernateTransa ctionManager">
<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

Torsten Juergeleit
Aug 29th, 2005, 07:54 AM
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).

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.

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.

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 (http://forum.springframework.org/viewforum.php?f=3) again.

Cheers,
Torsten

lorelia
Aug 29th, 2005, 11:00 AM
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

Torsten Juergeleit
Aug 29th, 2005, 08:29 PM
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.

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

lorelia
Aug 30th, 2005, 02:52 AM
Hey Torsten,

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

Lori