【问题标题】:How to enable spring transaction logger如何启用spring事务记录器
【发布时间】:2014-03-04 09:42:01
【问题描述】:

我正在尝试为 spring 3.1.3 启用事务记录器,但我在控制台中没有看到任何有关事务的消息。

我的spring spring-context.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:context="http://www.springframework.org/schema/context"
    xmlns:jee="http://www.springframework.org/schema/jee"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd" default-autowire="byName">


     <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close">
        <property name="driverClassName" value="${db.driverClass}" />
        <property name="url" value="${db.connectionURL}" />
        <property name="username" value="${db.username}" />
        <property name="password" value="${db.password}" />
    </bean> 

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager" 
        p:entityManagerFactory-ref="entityManagerFactory">
        <property name="persistenceUnitName" value="myUnit" />
    </bean>

    <bean id="eclipseLinkJpaVendorAdapter" class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
    </bean>

    <bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
        p:dataSource-ref="dataSource" 
        p:persistenceUnitName="myUnit"
        p:jpaVendorAdapter-ref="eclipseLinkJpaVendorAdapter">
        <property name="jpaPropertyMap">
            <map>
                <entry key="eclipselink.cache.shared.default" value="false" />
                <entry key="eclipselink.weaving" value="false" />
            </map>
        </property>
        <property name="loadTimeWeaver">
            <bean
                class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
        </property>
    </bean>

    <tx:annotation-driven transaction-manager="transactionManager" />

</beans>

我的 log4j.properties

log4j.rootLogger=INFO, DEBUG, stdout
log4j.logger.com.myCompany=INFO

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{dd.MM.yyyy HH:mm:ss} %-5p (%13F:%L) - %m%n


log4j.logger.org.springframework.orm.jpa=DEBUG
log4j.logger.org.springframework.transaction=DEBUG

我哪里做错了?

【问题讨论】:

    标签: java spring spring-mvc logging


    【解决方案1】:

    您是否使用 @Transactional 注释您的方法以使它们参与事务?

    【讨论】:

    • 是的,我注释了一些服务,但是我无法看到上面配置的日志消息
    • 当码头尝试部署应用程序时,我收到此消息:如果您的 webapp 需要一个事务管理器,请配置一个
    猜你喜欢
    • 2011-04-09
    • 2019-05-20
    • 1970-01-01
    • 2015-08-31
    • 1970-01-01
    • 2023-03-15
    • 2023-03-21
    相关资源
    最近更新 更多