採用されている基本的な建設環境:SpringMVC、MyBatis、MySQL、Tomcat Springトランザクション管理は、従来のグローバルトランザクション管理とローカルトランザクション管理の欠点を分解し、統一されたトランザクション管理モデルをあらゆる環境で使用できるようにし、コードを1回記述できます。次に、さまざまなトランザクション管理戦略を提供しますSpringMVCとMyBatisを使用し、サービスとコントローラーを宣言するために均一にラベル付けされています
サーバーで[構成ファイルをロードする]順序が起動するため、web.xml --- root-context.xml(springの構成ファイル)--- servlet-context.xml(springmvcの構成ファイル) .xml構成ファイルでは、コントローラーが最初にスキャンされますが、現時点では、サービスはまだ取得されていません(トランザクションの処理なしでは、トランザクション処理はありません。容量)、したがって、root-context.xmlはコントローラーをスキャンしないでください。構成は次のとおりです。
<! - コンポーネントを自動的にスキャンします。コントローラーは、spring3-servlet.xmlで構成されています。 - > <コンテキスト:component-scanベースパッケージ= "com.sence"> <context:explude-filter type = "org.springframework.stertope.contr oller" /> > <! - コンポーネントを自動的にスキャンします。ControlRを削除すると、spring3-servlet.xmlで構成されます。 - > <コンテキスト:Component-scanベースパッケージ= "com.sence"> <context:explude-filter type = "annotation" = "org.springframework.stertope.contr oller" /> < /context:Component-Scan "Service-Context.xmlでコントローラーをスキャンしてください。サービスをスキャンしていない間、構成は次のとおりです。
<! - すべてのコントローラーをスキャンしますが、サービスをスキャンしないでください - > <コンテキスト:Component-scanベースパッケージ= "com.sence"> <context:include-filter type = "annotation" = "or。g.springframework.stereotype .Controller " /> <Context:explude-free type =" annotion "expression =" org.springframework.steeotype.service " /> < /context:component ---!コントローラーはサービスをスキャンしません - > <コンテキスト: Component-Scanベースパッケージ= "com.sence"> <context:include-filter type = "annotation" = "org.springframework.stereotype.contro ller" /> <コンテキスト:除外型= "annotation = "org.springframework.stertototy.service" /> < /context:component-scan>ステートメントの管理のために以下を構成できます。構成は次のとおりです。
<! - Transaction Manager、DataSourcetransactionAger-> <Bean Id = "Txmanager"> <プロパティ名= "dataSource" />> < /bean> <! - sprin-> <aop: config> <aop:pointcut id = "fooservicemethods" exposition = "execution(*com.sence。*。*。inpl。* = "fooservicemethods"/> </aop:config> <tx:advief id = "txadvice" trunaction-manager = "txmanager"> <tx:attributes> <method nam e = "find*" read- only = "true" /> <tx:method name = "love*" read-only = "true"/> <tx:method name = "*" lollback-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:advief id =" txadvice "transaction-manager =" txmanager "> <tx:attr ibutes> <tx:method name =" find*"read- only =" true "/ > <tx:method name = "load*" read-only = "true"/> <tx:method name = "*" lollback-for = "customexception"/>> </tx:属性> </tx:アドバイス>この時点で、私の構成が完了しましたが、テスト後、バッチのMySQLデータベーステーブルに行ったとき、オブジェクトの1つが間違っていて、Customexceptionの問題は実際にはわかりませんでした、手順は次のとおりです。1。エントリポイントが間違っている場合、宣言の宣言-Typeトランザクションが間違っているかどうかを見つけます