在昨天構建的Struts2項目上測試Spring2所需要的Jar包
結果
spring-core.jar
——>依賴:spring-web.jar
——>依賴:spring-context.jar
——>依賴:spring-beans.jar
——>依賴:commons-logging.jar
開始,單加入spring-core.jar,配置web.xml
<!-- ××××××××××××××× Spring配置和監聽 Start ××××××××××××××× -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/application*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- ×××××××××××××××× Spring配置和監聽 End ×××××××××××××××× -->
運行——
嚴重: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
解決——
缺少org.springframework.web.*,加入spring-web.jar
運行——
嚴重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContextException
Caused by: java.lang.ClassNotFoundException: org.springframework.context.ApplicationContextException
解決——
缺少org.springframework.context.*,加入spring-context.jar
運行——
嚴重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
java.lang.NoClassDefFoundError: org/springframework/beans/FatalBeanException
Caused by: java.lang.ClassNotFoundException: org.springframework.beans.FatalBeanException
解決——
缺少org.springframework.beans.*,加入spring-beans.jar
運行——
嚴重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
解決——缺少org.apache.commons.logging.*,加入commons-logging.jar
struts.xml加入<constant name="struts.objectFactory" value="spring" />
運行——
2010-3-3 20:53:35 com.opensymphony.xwork2.util.logging.commons.CommonsLogger error
嚴重: Dispatcher initialization failed
Unable to load configuration. - [unknown location]
Caused by: Cannot locate the chosen ObjectFactory implementation: spring - [unknown location]
......
2010-3-3 20:53:35 org.apache.catalina.core.StandardContext filterStart
嚴重: Exception starting filter struts2
Unable to load configuration. - [unknown location]
......
Caused by: Unable to load configuration. - [unknown location]
......
Caused by: Cannot locate the chosen ObjectFactory implementation: spring - [unknown location]
......
解決——找不到ObjectFactory,加入struts2-spring-plugin-2.1.8.1.jar
不是說struts2整合了spring之後,建立類對象會根據spring設定檔裡面的<bean>來配置嗎?
這裡並沒有做<bean>配置,但是一樣訪問成功了......
慣例PS:
發現文章有錯的請通知我,非常感謝!
來過的朋友請順便踩一腳......^_^