版权声明: https://blog.csdn.net/hu18315778112/article/details/84899755
因为struts导入了整合spring的jar包,所以项目启动时,会自动找spring的容器,如果找不到会报错,所以最好先配置spring容器。
注意:因为整合步骤可能需要很多操作和配置的书写,所以最好做一步测一步,不要全部配置完后才测试。
导入约束(四个):
- 1. beans
- 2. core
- 3. context
- 4. tx
配置Spring容器随项目启动而创建,在项目的web.xml中配置:
<!-- 配置Spring容器随项目启动而创建 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 配置Spring容器配置文件路径 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
到此,可以启动项目,测试下Spring配置是否正确
项目部署到tomcat出现:(请忽略我的垃圾电脑配置)
信息: Server startup in 16754 ms
而且没有报错,说明配置正确,可以进行下一步:struts2配置