标签:创建 请求 col class system public result 容器 efi
1.创建项目
2.导包:struts2-spring-plugin struts2-core
3.配置文件:web.xml spring-context.xml
web.xml:配置struts2的filert,配置spring的启动加载配置文件,配置spring的监听器
<!-- 配置spring监听,用于初始化spring容器 --> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <!-- 指定spring配置文件的位置 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring-*.xml</param-value> </context-param> <!-- struts2主控制器的配置 --> <filter> <filter-name>mvc</filter-name> <filter-class> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter </filter-class> </filter> <filter-mapping> <filter-name>mvc</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
spring-context.xml:配置spring扫描的包
控制层:
@Controller //每一个请求都创建一个Action @Scope("prototype") public class HelloAction { @Resource private DemoService demoService; private String message; public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } public String execute() { message="你好"; demoService.hello(); System.out.println("helloworld"); return "success"; } }
Service层
@Service("demoService") public class DemoServiceImpl implements DemoService{ public void hello() { System.out.println("Service Hello"); } }
标签:创建 请求 col class system public result 容器 efi
原文地址:https://www.cnblogs.com/xhwr/p/11160677.html