1. 如果在web.xml和struts-config.xml文件中均不配置 会报以下的错误:
java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?
org.springframework.web.context.support.WebApplicationContextUtils.getRequiredWebApplicationContext(WebApplicationContextUtils.java:84)
org.springframework.web.struts.DelegatingActionUtils.findRequiredWebApplicationContext(DelegatingActionUtils.java:122)
org.springframework.web.struts.ActionSupport.initWebApplicationContext(ActionSupport.java:98)
org.springframework.web.struts.ActionSupport.setServlet(ActionSupport.java:78)
com.p2a.web.action.SearchAllAction.setServlet(SearchAllAction.java:37)
org.apache.struts.action.RequestProcessor.processActionCreate(RequestProcessor.java:341)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:268)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
web.xml部分配置1:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
web.xml部分配置2:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<servlet>
<servlet-name>SpringContextServlet</servlet-name>
<servlet-class>
org.springframework.web.context.ContextLoaderServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
以上两种均可以,已经试验成功。
在struts-config.xml文件中配置如下:
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation" value="/WEB-INF/applicationContext.xml" />
</plug-in>
如果还有其他的xml文件可以一起声明加进来。在value中以逗号分割。
2. Error creating bean with name 'sessionFactory' defined in ServletContext resource
[/WEB-INF/applicationContext.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: javax/transaction/TransactionManager
解决方案:
在webinf下加jta.jar包。