기본 건설 환경 채택 : SpringMVC, Mybatis, MySQL, Tomcat Spring Transaction Management 그런 다음 다른 환경에서 다른 거래 관리 전략을 제공합니다. 하나는 선언적 거래 관리 전략입니다 SpringMVC 및 MyBatis를 사용하면 서비스 및 컨트롤러를 선언하도록 균일하게 레이블이 붙어 있습니다.
서버에서 구성 파일을로드하는 순서는 web.xml --- root-context.xml (spring의 구성 파일) --- spring-context.xml (springmvc의 구성 파일)입니다. .XML 구성 파일에서 컨트롤러가 먼저 스캔되지만 현재로서는 서비스가 아직 향상되지 않았으므로 트랜잭션 처리 없이는 원래 서비스입니다. 용량), 우리는 루트 -context.xml에 있어야합니다. 컨트롤러를 스캔하지 않으므로 구성은 다음과 같습니다.
<!-구성 요소를 자동으로 스캔하면 컨트롤러가 제거되지 않으면 트랜잭션 관리에 영향을 미칩니다. -> <context : component-scan base-package = "com.sence"> <context : "주석"= "org.springframework.sterotype.contr oller" /> > <!-구성 요소를 자동으로 스캔하면 컨트롤러에서 컨트롤러가 제거되지 않으면 트랜잭션 관리에 영향을 미칩니다. -> <context : component-scan base-package = "com.sence"> <context : exclude-filter type = "주석"= "org.springframework.sterotype.contr Oller" /> < /context : component-scan "Service-context.xml의 스캔 컨트롤러 서비스를 스캔하지 않고 구성은 다음과 같습니다.
<!-모든 컨트롤러를 스캔하지만 서비스-> <context : component-scan base-package = "com.sence"> <context : include filter type = "annotation"= "또는. g.springframework.stereotype .controller " /> <context : free-free type ="annotion "expression ="org.springframework.steeotyp.service " /> < /context : component ---! 컨트롤러이지만 서비스를 스캔하지 않습니다-> <context : Component-Scan Base-Package = "com.sence"> <context : filter type = "annotation"= "org.springframework.stereotyp.contro ller" /> <context : filder type = "주석" = "org.springframework.sterotype.service" /> < /context : component-scan>다음은 명령문 관리를 위해 구성 할 수 있으며 구성은 다음과 같습니다.
<!-트랜잭션 관리자, DataSourcetransactionAger-> <bean id = "txmanager"> <property name = "dataSource"ref = "dataSource" /> < /bean> <!-스프린. config> <aop : pointcut id = "fooservicemethods"exposition = "execution (*com.sence.*.*. empr.*.*(..))"<aop : Advisor Advice-Ref = "txadvice"pointcut-ref = "fooservicemethods"/> </aop : config> <tx : 조언 id = "txadvice"transaction-manager = "txmanager"> <tx : attributes> <method nam e = "find*"read- 만 ""true " /> <tx : 메소드 이름 = "love*"read-for = "true"/> <tx : method name = "*"rollback-for = "customexception"/> </tx : 속성> </tx : 조언 > <!-트랜잭션 관리자, DataSourcetRansactionAger-> <bean id = "txmanager"> <속성 이름 = "dataSource"ref = "dataSource"/> </> bean> <!-스프링 선언 트랜잭션 관리-> <aop : config> <aop : pointcut id = "fooservicemethods"expression = "execution (*com.sence.*.*.*. "/> </aop : config> <tx : 조언 ID ="txadvice "transaction-manager ="txmanager "> <tx : att > <tx : 메소드 이름 = "load*"read-for = "true"/> <tx : method name = "*"rollback-for = "customexception"/> </tx : 속성> </tx : 조언>이 시점에서 내 구성이 완료되었지만 테스트 후 MySQL 데이터베이스 테이블에 배치를했을 때 객체 중 하나가 잘못되었으며 CustomeXception 업무가 실제로 돌아 오지 않았습니다 , 단계는 다음과 같습니다. 1. 진입 지점이 잘못되면 선언 선언 -유형 거래가 잘못되었는지 여부를 찾으십시오.