SSM整合
S:springmvc S:spring m:mybatis
意义:
Web层:springmvc
Service层:spring(对象的创建 aop事务)
Dao层:mybatis
步骤:
整合(自己能写出来):
1 单独测试service层 让spring先跑起来
坐标
配置文件(application)
UserSerivice--UserServiceImpl--findAll()
2 单独测试dao层 让mybatis先跑起来
坐标
配置文件(映射文件 数据库核心配置文件sqlMapConfig.xml)
UserDao 基于接口的动态代理方式
3 整合service和dao层 spring+mybatis
坐标(整合包)
整合:如何注入userDao的实现类(mybatis基于动态代理产生的)
整合:事务
4 单独测试web层 让springmvc先跑起来
坐标
配置文件(spring-mvc.xml)
5 整合web层+service层+dao层 springmvc+spring+mybatis(ssm)
整合:在controller中注入service
解决方案1:服务器启动既加载spring-mvc.xml也加载application.xml
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-mvc.xml,classpath:application.xml</param-value>
</init-param>
解决方案2:在web.xml中使用spring提供的监听器加载application.xml文件
<!--配置一个加载spring配置文件的监听器 只要服务器启动 该监听器就去加载-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:application.xml</param-value>
</context-param>