使用SSM整合项目

1、整合SSM
a、导入之前整合的Spring+MyBatis
b、配置监听器启动Spring的IoC容器(或者直接在springmvc.xml引入spring.xml)

<listener>
        <listener-class>
  org.springframework.web.context.ContextLoaderListener
 </listener-class>
</listener>
<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:beans.xml</param-value>  //spring配置beans.xml
</context-param>

注意:MyBatis没有Spring事务管理的问题:(直接在springmvc.xml引入spring.xml不会有事务问题)

第一种情况:
两个容器产生两套控制器和业务类,请求调用的是springmvc容器的而事务是控制在spring容器上!

解决:MVC的springmvc.xml配置文件中只扫描包含controller的注解,Spring的beans.xml文件中扫描包时,排除controller的注解,如下所示:

SpringMVC的xml配置:

<context:component-scan base-package="com.cssl.controller"/> 

Spring的xml配置:(不扫描带有@Controller注解的类,因为这些类在springmvc.xml中扫描)

<context:component-scan base-package="com.cssl">           
    <context:exclude-filter type="annotation"                                   expression="org.springframework.stereotype.Controller"/>
</context:component-scan>

只用一个配置文件:(相当直接在springmvc.xml引入spring.xml)

第二种情况:MySQL数据没用InnoDB引擎,修改数据库引擎即可

2、Web获取当前的SpringIoC容器
方法一:(通过ServletContext加载spring容器,SpringBoot适用)

ApplicationContext ctx=WebApplicationContextUtils.getWebApplicationContext(application);

方法二:(获取当前的spring容器,任何java类中适用)

WebApplicationContext act=ContextLoader.getCurrentWebApplicationContext();

3、防止Spring内存溢出监听器

<listener>
    <listener-class>
  	org.springframework.web.util.IntrospectorCleanupListener
    </listener-class>
</listener>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值