主要就是几个配置文件: web.xml 2.spring-mvc.xml 3.spring-mybatis.xml
1.web.xml :加载spring-mybatis.xml配置文件, 加载spring配置文件,监听,以及配置文件spring-mvc.xml的位置, 编码过滤,log4j配置文件,监听
2.spring-mvc.xml: 注解驱动 ,视图解析器
3.spring-mybatis.xml
3.1注解驱动,扫描到service层;
3.2 PropertyPlaceholderConfigurer 引入jdbc.properties 配置文件;
3.3 BasicDataSource 加载数据库驱动,url,用户名,密码 ;
3.4 SqlSessionFactoryBean,用来加载数据源以及mapping/*.xml
3.5 MapperScannerConfigurer 用来扫描Dao
3.6 DataSourceTransactionManager 事物管理
<!--==12.1注解驱动 自动扫描该包,使SpringMVC认为包下用了@controller注解的类是控制器 -->
<context:component-scan base-package="com.eaju" />
<!-2.2 定时器配置
<bean id="UnifiedOrderServiceImpl" class="com.eaju.service.impl.UnifiedOrderServiceImpl"></bean>
<task:scheduled-tasks>
<task:scheduled ref="UnifiedOrderServiceImpl" method="findAllOrder" cron="*/8 * * * * ? "></task:scheduled>
<!-- <task:scheduled ref="UnifiedOrderServiceImpl" method="findAllOrder" cron="0 0/1 * * * ?"></task:scheduled> -->
</task:scheduled-tasks>
<!--2.3 视图解析器 =============定义跳转的文件的前后缀 ,视图模式配置 -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- 这里的配置我的理解是自动给后面action的方法return的字符串加上前缀和后缀,变成一个 可用的url地址 -->
<property name="prefix" value="/WEB-INF/view/" />
<property name="suffix" value=".jsp" />
</bean>
内容:
--1.0.0头文件
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
--1.0.1 spring 配置,加载spring-mybatis.xml配置文件
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpatch:spring-mybatis.xml<>
<context-param/>
--1.0.2 编码过滤
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<!----1.0.3 Log4j配置 -->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.properties</param-value>
</context-param>
<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>6000</param-value>
</context-param>
<!-- 加载log4j配置文件,监听 -->
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<!-- 加载spring配置文件,监听,以及配置文件spring-mvc.xml的位置 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>