1、配置pom.xml文件,导入依赖的jar和环境
2、创建java、resources、创建domain、dao、service、controller编写实体类Account、编写持久层接口AccountDao、编写业务层接口AccountService、编写业务层实现类impl.AccountServiceImpl
做整合,必须保证每个框架都能单独去使用,spring去整合其他框架,先搭建spring框架。
一、搭建Spring框架的环境
1、service和dao交给IOC去管(创建spring的配置文件applicationContext.xml)
@Service("accountService")业务层交给容器去处理
新建test.TestSpring对spring进行测试(更改测试类的范围、添加log4j.properties的配置文件)
spring环境搭建OK
二、搭建SpringMVC框架的环境
web.xml中配置前端控制器和过滤器
创建springmvc.xml的配置文件
编写index.jsp测试Controller控制器(编写控制器和list.jsp)
springMVC环境搭建成功
三、Spring整合SpringMVC框架
controller控制层,如果可以调用业务层说明整合成功了
启动服务器的时候applicationContext.xm(spring的配置文件)也要加载。Spring整合SpringMVC,启动tomcat服务器的时候,需要加载Spring的配置文件。
spring-web提供监听器的类,会帮我们加载spring的配置文件
在web.xml中添加监听器
(方式启动服务器加载spring容器,然后在Controller中注入service的对象就可以了)
spring整合springMVC彻底成功了
四、搭建Mybatis框架的环境
AccountDao中创建接口(使用注解的方式),创建Sql语句
1、编写SqlMapConfig.xml配置文件
<!--配置具体的环境-->
<!--配置要引入映射配置文件 -->
编写test.TestMybatis类,测试Mybatis类是否搭建完成
mybatis框架环境搭建完成
查询可以不管事务,增删改必须注意事务
五、Spring整合Mybatis框架
核心点,Dao层把生成的代理对象怎么存到IOC的容器里,然后在service拿到对象注入
<!--Spring整合Mybatis框架-->
<!--配置SqlSessionFactory工厂-->
<!--配置AccountDao-->
AccountDao添加: @Repository
AccountController中添加: @Autowired private AccountDao accountDao;
spring和mybaits整合完成
修改AccountServiceImpl、AccountController
7、添加声明式的事务管理,保存可以实现,说明框架搭建成功
< !--配置Spring框架声明式事务管理-->
<!--配置事务管理器-->
<!--配置事务通知-->
<!--配置Aop增强-->
SSM整合成功
Eclipse_SSM环境搭建
1、新建项目,project。Maven project。点击next。
pom.xml文件。添加所需要的jar包。
web.xml文件。
要想实现SSM的整合就要编写Web应用程序主配置文件web.xml、Spring配置文件和Spring MVC配置文件。
dispatcherServlet-servlet.xml
在src/main/webapp/WEB-INF目录中,创建Spring MVC配置文件,文件名为dispatcherServlet-servlet.xml
applicationContext.xml
在src/main/resources目录中,创建Spring配置文件,文件名为applicationContext.xml
dbconfig.properties
在src/main/resources目录中,创建配置文件,文件名为dbconfig.properties