I've got a Spring maven project separated, myapp.web contains only JSPs and static files, while myapp.core contains app context XMLs and Controllers.
myapp.core
-- src/main/resources/context.xml
-- src/main/resources/mvc-context.xml
myapp.web
-- src/main/webapp/WEB-INF/web.xml
web.xml contains root context configuration and servlet configuration
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:/context.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
...
<servlet>
<servlet-name>servlet0</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:/mvc-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>servlet0</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
I also have OpenSessionInViewFilter
configured
<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</filter-class>
<init-param>
<param-name>flushMode</param-name>
<param-value>AUTO</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Now, generating the war from myapp.web and dropping in Tomcat manually works fine. But, when running from Eclipse via "Run On Server", OpenSessionInViewFilter
does not see sessionFactory
which is configured in context.xml I tried fixing build path of project but it won't run.
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'sessionFactory' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:529)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1094)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:276)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1079)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.lookupSessionFactory(OpenSessionInViewFilter.java:242)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.lookupSessionFactory(OpenSessionInViewFilter.java:227)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:171)
Now I know this is a Eclipse/m2e-wtp configuration issue since it's working by manually deploying but I've been unable to fix it. Played with Build Path of project as is usually suggested but no success.
Thanks
Check if the xml files in myapp.core are at the classpath when you run your application via eclipse. Most likely they aren't. You can check by using something like
if (getClass().getResource("my context-xml file") ! = null) {
System.out.println("No context file on the classpath, won't work");
}
Problem could be that Eclipse is configured no to copy the xml files to the bin directory.
Solved. The problem was this: Context was auto-reloading(not sure why)! myapp.core used to be the entry point(web app). After splitting, it had a missing tick on Project Facets called Utility Project , and Maven Integration for Eclipse was not deploying this project as a jar!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.