春季休眠事务日志
问题描述:
我们怎样才能记录spring事务机制。我显示下面的例子Spring Doc sec 10.5.2如果我想记录到这个级别如何做到这一点春季休眠事务日志
我使用的是Spring,Hibernate和Log4j。
<!-- the Spring container is starting up... -->
[AspectJInvocationContextExposingAdvisorAutoProxyCreator] - Creating implicit proxy
for bean 'fooService' with 0 common interceptors and 1 specific interceptors
<!-- the DefaultFooService is actually proxied -->
[JdkDynamicAopProxy] - Creating JDK dynamic proxy for [x.y.service.DefaultFooService]
<!-- ... the insertFoo(..) method is now being invoked on the proxy -->
[TransactionInterceptor] - Getting transaction for x.y.service.FooService.insertFoo
<!-- the transactional advice kicks in here... -->
[DataSourceTransactionManager] - Creating new transaction with name [x.y.service.FooService.insertFoo]
[DataSourceTransactionManager] - Acquired Connection
[[email protected]] for JDBC transaction
<!-- the insertFoo(..) method from DefaultFooService throws an exception... -->
[RuleBasedTransactionAttribute] - Applying rules to determine whether transaction should
rollback on java.lang.UnsupportedOperationException
[TransactionInterceptor] - Invoking rollback for transaction on x.y.service.FooService.insertFoo
due to throwable [java.lang.UnsupportedOperationException]
<!-- and the transaction is rolled back (by default, RuntimeException instances cause rollback) -->
[DataSourceTransactionManager] - Rolling back JDBC transaction on Connection
[[email protected]]
[DataSourceTransactionManager] - Releasing JDBC Connection after transaction
[DataSourceUtils] - Returning JDBC Connection to DataSource
Exception in thread "main" java.lang.UnsupportedOperationException
at x.y.service.DefaultFooService.insertFoo(DefaultFooService.java:14)
<!-- AOP infrastructure stack trace elements removed for clarity -->
at $Proxy0.insertFoo(Unknown Source)
记录文件..
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
log4j.rootLogger=info, stdout
log4j.category.org.springframework.transactions=DEBUG
答
Spring Reference中有a section about Logging。
它显示了如何配置不同的日志框架,其中log4j
在你的情况下,配置的最后一行是:
log4j.logger.org.springframework.transaction=DEBUG
答
如果你只愿意设置的Spring的事务支持的日志级别,尝试添加下面的记录到你的log4j.xml:
<logger name="org.springframework.transaction">
<level value="DEBUG" />
</logger>
@Lucas感谢..我已经把我的Log4j属性文件above.can你建议soem的变化,这可以帮助我使用Spring登录我的j2ee应用程序,hibernate – Vish 2011-05-06 05:19:23
我们是否需要一些使用log4j.category的配置,因为这不适用于我的应用程序。 :( – Vish 2011-05-06 05:28:52
@Vish我从Spring文档中复制了它,但是无法在log4j文档中找到它。现在更改为'logger' – 2011-05-06 07:31:38