1、spring主配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<!--第一步,扫描service-->
<context:component-scan base-package="com.zmh.ssm.service.impl"></context:component-scan>
<!--第二步,加载jdbc.properties-->
<context:property-placeholder location="classpath:jdbc.properties"></context:property-placeholder>
<!--第三步,创建dbcp数据源连接池-->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${driver}"></property>
<property name="url" value="${url}"></property>
<property name="username" value="${user}"></property>
<property name="password" value="${password}"></property>
</bean>
<!--第四步,创建mybatis的工厂类对象-->
<bean class="org.mybatis.spring.SqlSessionFactoryBean">
<!--指定数据源-->
<property name="dataSource" ref="dataSource"></property>
<!--加载mybatis的映射文件 在value中可以使用*号通配符-->
<property name="mapperLocations" value="classpath:mapper/*.xml"></property>
</bean>
<!--第五步,在spring的工厂中生成dao接口的实现类对象-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!--指定要扫描哪个包下面所有的dao接口-->
<property name="basePackage" value="com.zmh.ssm.dao"></property>
</bean>
<!--第六步,创建spring的事物管理器-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!--第七步,声明以注解的方式配置声明式事物-->
<tx:annotation-driven transaction-manager="transactionManager"></tx:annotation-driven>
</beans>

2、spring-mvc主配置文件

 <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!--扫描控制器包-->
<context:component-scan base-package="com.zmh.ssm.controller"></context:component-scan>
<!--声明以注解的方式配置spring mvc 相当于配置类
RequestMappingHandlerMapping 处理器映射器
RequestMappingHandlerAdapter 处理器适配器
-->
<mvc:annotation-driven></mvc:annotation-driven>
<!--配置spring mvc默认的jsp视图解析器-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!--配置返回视图的前缀-->
<property name="prefix" value="/WEB-INF/jsp/"></property>
<!--配置返回视图的后缀-->
<property name="suffix" value=".jsp"></property>
</bean>
</beans>

3、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_4_0.xsd"
version="4.0">
<!--配置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>
<!--配置spring mvc的前端控制器-->
<servlet>
<servlet-name>spring-mvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!--指定spring mvc的主配置文件的位置和名称-->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-mvc.xml</param-value>
</init-param>
</servlet> <servlet-mapping>
<servlet-name>spring-mvc</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<!--配置编码过滤器,解决post请求中文乱码问题-->
<filter>
<filter-name>characterEncodingFilter</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>forceResponseEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>

最新文章

  1. 读书笔记--SQL必知必会03--排序检索数据
  2. 内存,堆,栈,heap,stack,data
  3. POJ 1775 (ZOJ 2358) Sum of Factorials
  4. shouldOverrideUrlLoading相关说明
  5. 基于visual Studio2013解决C语言竞赛题之0524职工年龄
  6. MySQL模式 : Strict Mode
  7. redo log
  8. s15day14 ssh秘钥远程连接
  9. 洛谷 P2904 [USACO08MAR]跨河River Crossing
  10. ES6(阮一峰)学习总结
  11. 【爆料】-《昆士兰大学毕业证书》Queensland一模一样原件
  12. Java中的常用集合类型总结
  13. python基础之作业1---用户登录
  14. 潭州课堂25班:Ph201805201 django 项目 第二课 git 版本控制 (课堂笔记)
  15. 【AtCoder】ARC103
  16. 6. 支持向量机(SVM)核函数
  17. noip2007部分题
  18. java concurrent包的实现原理
  19. POJ 2663 Tri Tiling 矩阵快速幂 难度:3
  20. 【LG3245】[HNOI2016]大数

热门文章

  1. light oj 1104 Birthday Paradox (概率题)
  2. Java基础之封装
  3. LOFTER 迁移
  4. 各浏览器对 window.open() 的支持
  5. cobbler dell r730安装问题(四)
  6. ubuntu检测到系统错误解决方法
  7. Jeddict:怎样在window系统下,成功打包Angular
  8. 九度oj 题目1041:Simple Sorting
  9. jQuery实现当按下回车键时绑定点击事件
  10. 设计模式(二 &amp; 三)工厂模式:3-抽象工厂模式