用idea8.1 写的,程序自动加载了struts2,spring的包,
不过缺少了struts2-spring-plugin-2.1.6.jar这个包(注意要与struts版本相同)
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath*:applicationContext-*.xml
</param-value>
</context-param>
</web-app>
struts.xml
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"
"http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.objectFactory" value="spring" />
<package name="/" extends="struts-default">
<action name="helloTest" class="helloPOJO" method="helloTest">
<result name="success">/test/hello.html</result>
</action>
</package>
</struts>
applicationContext-test.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="helloPOJO" class="test.HelloPOJO">
<property name="src">
<value>HeLLo</value>
</property>
</bean>
</beans>
test包HelloPOJO类
public class HelloPOJO extends ActionSupport {
public void setSrc(String src) {
this.src = src;
}
public String helloTest(){
System.out.print(src);
return SUCCESS;
}
String src;
}