Spring整合SpringMvc時事務失效
最近在做一個新專案是剛搭建的框架(springMVC+spring+hibernate),然後在呼叫自己介面的時候發現一個問題事務失效了,資料並沒有提交到資料庫中去,然後就開始檢視spring中事務配置的部分我是這麼配置的
找了半天沒有發現配置有什麼問題,然後就去網上搜索這到底是什麼問題,後來找資料發現其實Spring和SpringMVC倆個容器為父子關係,Spring為父容器,而SpringMVC為子容器。也就是說application.xml中應該負責掃描除@Controller的註解如@Service,而SpringMVC的配置檔案應該只負責掃描@Controller,否則會產生重複掃描導致Spring容器中配置的事務失效。
也就是說spring先掃描要新增事務的包或者類然後再由springMVC掃描的話加上的事務就會失效.
解決方法就是在掃描配置中加上過濾就是這種
在spring配置檔案中用過濾器排除掃描加過@Controller的類然後springMVC配置檔案中只掃描帶@Controller的類排除@Service註解的類.
最後測試一下問題解決!
相關推薦
Spring整合SpringMvc時事務失效
最近在做一個新專案是剛搭建的框架(springMVC+spring+hibernate),然後在呼叫自己介面的時候發現一個問題事務失效了,資料並沒有提交到資料庫中去,然後就開始檢視spring中事務配置
mybatis整合spring、springmvc時業務層無法進行事務回滾問題解決
前言:近期換了新公司,剛來公司就接觸了一下mybatis,因為springmvc和spring比較熟悉,我想大概現在絕大部分的公司都在用吧,剛接觸mybatis時感覺真心蛋疼,純sql才處理業務,實在是有點不習慣,不過感覺整個框架較之前的orm架構確實感覺速度快一點。 好
Spring整合mybatis時使用事務管理器
lang pan lan -s error org 版本 batis java 異常報告:java.lang.AbstractMethodError: org.mybatis.spring.transaction.SpringManagedTransaction.getTi
關於在整合mybatis、spring、springmvc時出現的Invalid bound statement (not found): 錯誤
今天在使用ssm框架進行ajax使用測試的時候,copy了教學視訊的程式碼,程式結構如下: sping的關於mybatis的配置語句如下: <!-- mapper的加強————————1.配置SqlSessionFactory --> <bean class="org
在Spring整合 SpringMVC,SpringData和 JPA 時,如何解決 Lazy懶載入問題?
/*** @ManyToOne(fetch=FetchType.LAZY)* 如在關聯屬性時,fetch的值 設定為Lazy , 則在頁面上呼叫是會出現懶載入異常* javax.el.ELExcep
Spring 整合 Hibernate 時啟用二級緩存實例詳解
如果 property ear spring3 ont 狀態 keyword www 永遠 寫在前面: 1. 本例使用 Hibernate3 + Spring3; 2. 本例的查詢使用了 HibernateTemplate; 1. 導入 ehcache-x.
spring整合springmvc和mybatis中的基本配置檔案
1 父工程統一管理依賴的porm.xml檔案 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLoca
Spring整合mybatis時,資料庫配置com.mysql.jdbc.Driver和com.mysql.cj.jdbc.Driver區別
1、#mysql-connector-java 5 用法 spring.datasource.driver-calss-name=com.mysql.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnico
Spring整合SpringMVC
b- 文件 ews 4.0 public 數據 tco sca 事務 service: package com.atguigu.springmvc; import org.springframework.beans.factory.annotation.Autowire
使用spring整合mybatis時,通過spring載入的mapper操作怎麼回滾
1 錯誤程式碼: try{ ApplicationContext app = new ClassPathXmlApplicationContext("applicationContext.xml");
簡單探討spring整合mybatis時sqlSession不需要釋放關閉的問題
近期,在使用spring和mybatis框架編寫程式碼時,sqlSession不需要手動關閉這一點引起了我的興趣。我們都知道,單獨使用mybatis時,sqlSeesion使用完畢後是需要進行手動關閉的,但為什麼在和spring整合後就不需要了呢?在查閱了資料後得知,這是使用了spring中的AOP面向切面程
spring整合activity時啟動報Tables missing for component(s) engine, history, identity
Caused By: org.activiti.engine.ActivitiException: Activiti database problem: Tables missing for component(s) engine, history, identity
maven 專案(五) spring整合springMVC開發統一接入API--實現test介面
為什麼要採用測試介面的方式:貼完程式碼我再來說; 1.貼張圖片 2.是測試介面地址的暴露方式: @Controller public class ApiTestController { @Value("${epeit.api.server}") private St
maven 專案(四) spring整合springMVC開發統一接入API(準備工作:第二部分)
介面虛擬碼流程(為啥是虛擬碼,這裡就是很一般的寫法,給人蔘考吧):/** @Controller:宣告是springMVC的響應元件 @RequestMapping(value = "/apicenter"):定義介面路徑 */ @Controller public class Api
SpringMVC_27_需要進行Spring 整合SpringMVC嗎?和整合值得注意的地方
->需要進行Spring 整合SpringMVC嗎? ->還是否需要再加入Spring的IOC容器? ->是否需要在web.xml檔案配置啟動Spring IOC容器的 ContextLoaderListener? 1.需要 通常情況下,類似於資料來源,事務,
Spring學習5-Spring整合JDBC及其事務處理(註解方式)
2、步驟二:使用JdbcTemplate類操作資料庫: Spring把JDBC中重複的操作建立成了一個模板類:org.springframework.jdbc.core.JdbcTemplate。 A:要使用JdbcTemplate,需要為每一個DAO配置一個JdbcTemplate例項:
SSM進階(四)Spring整合Mybatis-----Aop事務
Spring整合Mybatis-----Aop事務 首先對於Spring整合Mybatis有兩種方式那就是使用sql絕對定位以及使用Mapper代理來進行開發,本篇博文先來介紹第一種。 所謂的Sql絕對定位就是namespace+id得方式來進行定位
Spring整合MyBatis進行事務管理
1、引入的Spring和MyBatis依賴的jar包 引入c3p0.jar與mchange-commons.jar是為了使用資料庫連線池,資料庫連線池會在MyBatis以及Spring的事務管理器介面PlatformTransactionManager中使用到。
Spring整合Dubbo時XML報錯解決
spring整合dubbo時,xml配置檔案也遇到過這種情況。 dubbo配置檔案報錯 在配置dubbo服務的過程中,經常會遇到雖然程式能夠跑起來,但是配置檔案一堆紅叉,雖然不影響功能,但是確實很讓人噁心。 報錯資訊如下: Multiple annotations
mybatis整合springmvc時的錯誤org.apache.ibatis.binding.BindingException: Invalid bound statement (not found
今天在除錯mybatis,新增一個搜尋功能的時候報了一個這個錯誤 <span style="white-space:pre"> </span>rg.springframewor