SSH与SSM学习之SSH整合02——单独配置Spring容器
一、创建一个Action
创建的这个Action,其实只是为了不让 Spring 的配置不问空而已,其他目前没什么用。
package com.qwm.ssh_crm.web.action;
import com.opensymphony.xwork2.ActionSupport;
/**
* @author:qiwenming
* @date:2017/11/1 0001 23:37
* @description:
*/
public class UserAction extends ActionSupport{
}
二、配置Spring的配置文件
applicationContext.xml
<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd ">
<bean name="userAction" class="com.qwm.ssh_crm.web.action.UserAction"/>
</beans>
三、配置Spring随项目启动
这个配置,我们在 web.xml 中配置
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<!-- 让spring随web启动而创建的监听器 -->
<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>
</web-app>
四、运行
配置好了以后,运行看一下,不出错,再往下配置。