struts 2 有感 待續
覺得 struts2 的官方網站上的第一個例子不是太好, 我開始試的時候,
把 struts2 的所有的 jar 包 都放到web-inf/lib 下了, 結果老出錯
就是下面的兩個錯:
-------------------------------------------------------------------
Unable to load bean: type:com.opensymphony.xwork2.ObjectFactory class:org.apache.struts2.spring.StrutsSpringObjectFactory - bean - jar:file:/D:/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/testStruts/WEB-INF/lib/struts2-spring-plugin-2.0.6.jar!/struts-plugin.xml:8:132
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:208)
at org.apache.struts2.config.StrutsXmlConfigurationProvider.register(StrutsXmlConfigurationProvider.java:101)
Caused by: java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContextAware
---------------------------------------------------------------------
其他的地方都檢查了好幾遍 但是一運行tomcat 就出錯, 找了半天原因原來是
沒看到下面這句話 http://struts.apache.org/2.x/docs/simple-setup.html
If any Struts 2 Plugins are included, then other JARs may be needed too. For example, the optional Spring Plugin requires the Spring JARs to be present.
這對初學者也要求太高了吧, 要是不知道 Spring 是的什麼東西就不要用struts2 了。
去掉了那幾個jar包, (簡單的,留下xwork-2.0.4.jar、commons-logging-1.0.4.jar、freemarker-2.3.8.jar、ognl-2.6.11.jar、struts2-core-2.0.11.jar)就可以運行了。