English 中文(简体)
Spring Mybatis Tomcat——不使用春天的交易
原标题:Spring Mybatis Tomcat - Transactions not using Spring

春天交易没有使用《禁止酷刑公约任择议定书》进行以下配置。

spring: version: 3.1.2.RELEASE
spring.ws:version:2.0.5.RELEASE
Mybatis: version:3.1.1
Database: Oracle 11g
Datasource connection:com.oracle.ojdbc6.11.2.0
Server : Tomcat : apache-tomcat-6.0.32

We are trying to create transactional service using AOP declarative transaction implementation. The setup is working fine with transactions being created as expected during Integration test, but while running the test from SoapUi using the endpoints, on local Server(Tomcat), All the transactions are non-transactional (can see the same in log files)

SPRING-DAOS.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:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd 
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

<!-- enable the configuration of transactional behavior based on annotations -->
<tx:annotation-driven transaction-manager="mywebappActiveTransactionManager" />

<aop:aspectj-autoproxy/>

<!-- ensure that the above transactional advice runs for any execution
of an operation defined by the Service interface -->
<aop:config>
    <aop:pointcut id="transactionalOperation" expression="execution(* com.org1.org2.mywebappgate.services.*.*(..)) "/>
    <aop:advisor advice-ref="txAdvice" pointcut-ref="transactionalOperation"/>
</aop:config>

<!-- the transactional advice (what  happens ; see the <aop:advisor/> bean below) -->
<tx:advice id="txAdvice" transaction-manager="mywebappActiveTransactionManager">
    <tx:attributes>
        <tx:method name="*" rollback-for="SQLException"/>
        <!-- <tx:method name="*" read-only="false" propagation="REQUIRED" /> -->
        <!--  <tx:method name="*" read-only="false" propagation="REQUIRED" />  -->
    </tx:attributes>
</tx:advice>


<jee:jndi-lookup id="mywebappActiveDataSource" jndi-name="java:/comp/env/jdbc/mywebapp-active" /> 

<bean id="mywebappActiveTransactionManager"
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="mywebappActiveDataSource" />
</bean>

<bean id="mywebappActiveSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="mywebappActiveDataSource" />
    <property name="configLocation" value="classpath:mybatis-config.xml" />
</bean>

<bean id="mywebappActiveMapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage" value="com.org1.org2.mywebappgate.dao" />
    <property name="sqlSessionFactoryBeanName" value="mywebappActiveSessionFactory" />
</bean>

Tomcat Context.xml

<Context>

<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>


<Resource auth="Container" driverClassName="oracle.jdbc.driver.OracleDriver" maxActive="20" maxIdle="10" maxWait="-1" name="jdbc/mywebapp-active" password="xxxxxx" type="javax.sql.DataSource" url="jdbc:oracle:thin:@mywebappdc1.company:1521:mywebappdc1" username="xxxxxx"/>

mybatis-config.xml

<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
    <!-- changes from the defaults -->
    <setting name="lazyLoadingEnabled" value="false" />
</settings>

<mappers>
    <mapper resource="company/mywebappgate/dao/SimpleCommentDao.xml" /> 
    <mapper resource="company/mywebappgate/dao/CommentDao.xml"/>
    <mapper resource="company/mywebappgate/dao/ARDAO.xml"/>
    <mapper resource="company/mywebappgate/dao/ASIndicatorsDao.xml"/>
</mappers>

Junit式测试仪:

org.mybatis.spring.SqlSessionUtils: Creating a new SqlSession
org.mybatis.spring.SqlSessionUtils: Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@c3c44]
org.mybatis.spring.transaction.SpringManagedTransaction: JDBC Connection [oracle.jdbc.driver.T4CConnection@1d5d765] will be managed by Spring
org.mybatis.spring.SqlSessionUtils: Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@c3c44]
org.mybatis.spring.SqlSessionUtils: Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@c3c44] from current transaction
org.mybatis.spring.SqlSessionUtils: Transaction synchronization committing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@c3c44]
org.mybatis.spring.SqlSessionUtils: Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@c3c44]
org.springframework.context.support.GenericApplicationContext: Closing org.springframework.context.support.GenericApplicationContext@1b4fad5: startup date [Wed Sep 05 14:16:30 EDT 2012]; root of context hierarchy
org.springframework.beans.factory.support.DefaultListableBeanFactory: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@69d02b: defining beans [org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,transactionalOperation,org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0,txAdvice

Tomcatlog:

org.mybatis.spring.SqlSessionUtils: Creating a new SqlSession
org.mybatis.spring.SqlSessionUtils: SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1e55d39] was not registered for synchronization because synchronization is not active
org.mybatis.spring.transaction.SpringManagedTransaction: JDBC Connection [jdbc:oracle:thin:@mywebapp1.company:1521:mywebapp1, UserName=user, Oracle JDBC driver] will not be managed by Spring
org.mybatis.spring.SqlSessionUtils: Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1e55d39]
org.mybatis.spring.SqlSessionUtils: Creating a new SqlSession
org.mybatis.spring.SqlSessionUtils: SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5b02a6] was not registered for synchronization because synchronization is not active
org.mybatis.spring.transaction.SpringManagedTransaction: JDBC Connection [jdbc:oracle:thin:@mywebappdc1.company:1521:mywebappdc1, UserName=mywebappSOA01, Oracle JDBC driver] will not be managed by Spring
问题回答

如果你正在使用春天,就不必在我方-*.xml中配置Xml。 你只是需要把一个财产列入我的网址。 活性成分:

<property name="mapperLocations" 
          value="classpath*:company/mywebappgate/dao//*Mapper.xml"/>

你的我的怀念会

<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
    <!-- changes from the defaults -->
    <setting name="lazyLoadingEnabled" value="false" />
</settings>




相关问题
Tomcat´s server.xml dynamic configuration

My web application uses the same database configuration as the application XYZ. I have a resource declaration for a context in server.xml, so I have a duplicated configuration (once for web ...

session transfer issue from Tomcat to ASP.Net

I am using Tomcat to host JSP and using IIS 7.0 to host aspx (C# + .Net 3.5 + VSTS 2008), and I have some session transfer issue from JSP page to ASPX page. JSP page is in one domain and all other ...

JSP exception - class not found (tomcat)

I m setting up an existing application on a new Tomcat 5.5 server connecting to a Postgres database (running on Debian Lenny). When I access it I get a series of stack traces with the following root ...

热门标签