当前位置: 首页 > news >正文

汽车之家网页版官网找车/宁波seo网站排名优化公司

汽车之家网页版官网找车,宁波seo网站排名优化公司,网站推荐几个免费的,一家专门做印刷的网站弄了一大早&#xff0c;终于配好了事务&#xff0c;事务的扫描包配好&#xff0c;Ehcache就是切面的问题&#xff0c;一切问题也迎刃而解。。。 一、Spring事务回滚 1、applicationContext.xml中配置 <!--spring 扫包 Service ..... --><context:component-scan ba…

弄了一大早,终于配好了事务,事务的扫描包配好,Ehcache就是切面的问题,一切问题也迎刃而解。。。

一、Spring事务回滚

1、applicationContext.xml中配置

<!--spring 扫包 @Service ..... --><context:component-scan base-package="com.yanhui"><context:exclude-filter type="annotation"expression="org.springframework.stereotype.Controller" /></context:component-scan>

2、spring-mvc.xml配置

<!-- 扫描器--><!-- <context:component-scan base-package="com.yanhui.*" /> --><context:component-scan base-package="com.yanhui" use-default-filters="false"><context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/></context:component-scan>

3、applicationContext.xml开启事务

<!-- (事务管理)transaction manager, use JtaTransactionManager for global tx --><bean id="transactionManager"class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dataSource" /></bean><!-- <tx:annotation-driven transaction-manager="transactionManager"/> --><tx:advice id="txAdvice" transaction-manager="transactionManager"><tx:attributes><tx:method name="publish*" /><tx:method name="save*" /><tx:method name="add*" /><tx:method name="update*" /><tx:method name="insert*" /><tx:method name="create*" /><tx:method name="del*" /><tx:method name="load*" /><tx:method name="init*" /><tx:method name="*"  read-only="true"/></tx:attributes></tx:advice><!-- AOP配置 --><aop:config><aop:pointcut id="myPointcut"expression="execution(public * com.yanhui.service..*.*(..))" /><aop:advisor advice-ref="txAdvice" pointcut-ref="myPointcut" /></aop:config>

4、测试

mapper.insert(record);
int a = 1/0;

二、Ehcache配置

1、引入jar包

<dependency><groupId>net.sf.ehcache</groupId><artifactId>ehcache-core</artifactId><version>2.6.11</version></dependency>

2、新建一个cache-config.xml

<?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:cache="http://www.springframework.org/schema/cache"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/cachehttp://www.springframework.org/schema/cache/spring-cache.xsd "><cache:annotation-driven cache-manager="cacheManager"/><bean id="ehcacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"><property name="configLocation" value="classpath:ehcache.xml"/></bean><bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager"><property name="cacheManager" ref="ehcacheManager"/><property name="transactionAware" value="true"/></bean>
</beans>

3、新建一个ehcache.xml

<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"updateCheck="false"><diskStore path="java.io.tmpdir"/><defaultCache eternal="false"maxEntriesLocalHeap="1000"overflowToDisk="false"diskPersistent="false"timeToIdleSeconds="3600"timeToLiveSeconds="3600"/><cache name="baseCache"eternal="false"maxEntriesLocalHeap="200"overflowToDisk="false"diskPersistent="false"timeToIdleSeconds="600"statistics="true"timeToLiveSeconds="600"/><!--eternal="false"   // 元素是否永恒,如果是就永不过期(必须设置)maxElementsInMemory="1000" // 缓存容量的内存最大值(必须设置)overflowToDisk="false"  // 当缓存达到maxElementsInMemory值是,是否允许溢出到磁盘(必须设置)diskPersistent="false"  // 磁盘缓存在VM重新启动时是否保持(默认为false)timeToIdleSeconds="0" // 导致元素过期的访问间隔(秒为单位). 0表示可以永远空闲,默认为0timeToLiveSeconds="600" // 元素在缓存里存在的时间(秒为单位). 0 表示永远存在不过期memoryStoreEvictionPolicy="LFU" // 当达到maxElementsInMemory时,如何强制进行驱逐默认使用"最近使用(LRU)"策略,其它还有先入先出FIFO,最少使用LFU,较少使用LRU-->
</ehcache>

4、applicationContext.xml中加入

 <import resource="cache-config.xml"/>

5、service.impl方法中

@Cacheable(value = "baseCache")public User findById(int id) {return userMapper.selectByPrimaryKey(id);}

6、测试
这里写图片描述

三、遇到的坑

spring、springMVC重复扫描导致事务失效的问题

意思是applicationContext.xml中扫描包和spring-mvc中的扫描包重复了,前者作为父容器先启动并配置了事务,然后spring-mvc.xml再启动,作为子容器也来管理包的内容,但是会覆盖前面applicationContext.xml对包的处理,而新的管理中并没有配置事务,所以事务就失败了。

经结论得出:
由于服务器启动时的加载配置文件的顺序为web.xml—root-context.xml(Spring的配置文件)—servlet-context.xml(SpringMVC的配置文件)。

解决办法:
Spring容器中不扫描Controller上的注解(即SpringMVC注解),SpringMVC层只负责扫描@Controller

http://www.jmfq.cn/news/5139523.html

相关文章:

  • 网站转移空间备案是不是就没有了/搜索引擎优化的基本手段
  • 怎样对一个网站做性能测试/优化网站怎么做
  • 网站防盗链怎么做/如何在百度做免费推广产品
  • 网站建设 统一质量标准/温州seo网站建设
  • 深圳网页定做/短视频搜索优化
  • 网站产品数据如何恢复/地推网app推广平台
  • 专门做店铺转让的网站/怎么开一个网站平台
  • 一家公司做两个网站/个人怎么在百度上做推广
  • 建筑工程网格化/黄山seo推广
  • 外贸网站运营怎么做/广州疫情最新消息今天封城了
  • 中小学网络云平台/深圳优化网站方法
  • 做跨境网站注意/推广品牌的方法
  • 电子简历模板/东莞网络推广及优化
  • 计算机网络设计/西安seo培训机构
  • 男女做羞羞事图片大全动态网站/哪些网站可以免费发广告
  • 北京做网站优化的公司/深圳网站页面设计
  • 深圳做微信网站建设/2021热门网络营销案例
  • 用帝国做网站好做吗/深圳关键词优化
  • 铁岭免费网站建设/河南品牌网络推广外包
  • 毕业设计指导网站开发/郑州外语网站建站优化
  • 西安专业做网站的公司/百度网址是多少
  • 平顶山 网站建设公司/一站式发稿平台
  • app开发公司平台/湖南seo博客seo交流
  • wordpress 歌词 插件/东莞网络优化公司
  • 网站建设金手指排名可靠/唐山seo快速排名
  • 罗湖网站建设费用/直销的八大课程
  • 高端大气的网站/域名查询入口
  • 怎么做旅行网站/杭州seo专员
  • 做自媒体怎么在其它网站搬运内容/互联网营销师考试
  • 六安网站线上引流多少钱/互联网推广销售好做吗