我已经从Spring Boot 1.3.2升级到1.4.0,但是现在无法启动我的应用程序-我BeanPostProcessor调用了3d第三方开源Lazy Chopper,而在尝试这样做时,它在getTransaction()这里失败了:
BeanPostProcessor
getTransaction()
public abstract class AbstractPlatformTransactionManager implements PlatformTransactionManager, Serializable { protected transient Log logger = LogFactory.getLog(getClass()); // ... @Override public final TransactionStatus getTransaction(TransactionDefinition definition) throws TransactionException { Object transaction = doGetTransaction(); // Cache debug flag to avoid repeated checks. boolean debugEnabled = logger.isDebugEnabled(); // logger is null here
当我在此处放置一个断点时,我可以看到logger确实是null,但是值得一提的是,如果我LogFactory.getLog(getClass())在此处调用自己,那我的确是正确的记录器。
logger
null
LogFactory.getLog(getClass())
似乎我的bean在初始化正确的Logger之前调用了该方法?
这是我得到的完整堆栈跟踪:
Caused by: java.lang.NullPointerException: null at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:340) ~[spring-tx-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:426) ~[spring-tx-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:275) ~[spring-tx-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) ~[spring-tx-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:168) ~[spring-aop-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:85) ~[spring-aop-4.3.2.RELEASE.jar:4.3.2.RELEASE] at com.tikal.lazychopper.DefaultLazyInitializationChopperAdvice.chop(DefaultLazyInitializationChopperAdvice.java:76) ~[lazy-chopper-1.2.8.jar:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_101] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_101] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_101] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_101] at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:629) ~[spring-aop-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:618) ~[spring-aop-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70) ~[spring-aop-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:168) ~[spring-aop-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655) ~[spring-aop-4.3.2.RELEASE.jar:4.3.2.RELEASE] at com.sapiens.bdms.core.service.impl.sign.hash.MD5StringCalculator$$EnhancerBySpringCGLIB$$b5747fb.getSignTypes(<generated>) ~[classes/:na] at com.sapiens.bdms.core.service.impl.sign.EntitySignCalculatorManagerImpl.postProcessAfterInitialization(EntitySignCalculatorManagerImpl.java:105) ~[classes/:na] at com.sapiens.bdms.core.service.impl.sign.EntitySignCalculatorManagerImpl$$FastClassBySpringCGLIB$$80ef4d8e.invoke(<generated>) ~[classes/:na] at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) ~[spring-core-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:720) ~[spring-aop-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655) ~[spring-aop-4.3.2.RELEASE.jar:4.3.2.RELEASE] at com.sapiens.bdms.core.service.impl.sign.EntitySignCalculatorManagerImpl$$EnhancerBySpringCGLIB$$91a9897b.postProcessAfterInitialization(<generated>) ~[classes/:na] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:422) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
我使用的是默认logback自动配置,没有任何调整。
logback
更新#1: 围绕该方法定义了切入点。
<aop:pointcut id="transactionManagerPointcut" expression="(execution(* org.springframework.transaction.PlatformTransactionManager.getTransaction(..)))"/>
更新#2: 因此似乎摆脱了这方面的窍门。.仍在试图找出原因和克服方法。
这是方面的定义:
<aop:pointcut id="transactionManagerPointcut" expression="(execution(* org.springframework.transaction.PlatformTransactionManager.getTransaction(..)))"/> <aop:pointcut id="allServices" expression="(execution(* com.decision..tx..*.*(..))) or (execution(* com.sapiens.bdms..tx..*.*(..))) && !@annotation(com.sapiens.bdms.core.persistence.annotation.NotTransactional)"/> <aop:aspect ref="sessionFilterConfigurator"> <aop:before method="setupFilter" pointcut-ref="allServices"/> <aop:after-returning method="setupFilter" pointcut-ref="transactionManagerPointcut"/> </aop:aspect>
这是aspect方法:
@Component("sessionFilterConfigurator") public class SessionFilterConfigurator { @Resource private Collection<FilterConfiguration> filterConfigurations; @Resource private SessionFactory sessionFactory; @Resource private FiltersDisconnector filtersDisconnector; public void setupFilter() throws Throwable { Session session = sessionFactory.getCurrentSession(); if (AutoEnableConfig.isFiltersEnabled()) { for (FilterConfiguration filterConfiguration : filterConfigurations) { Filter filter = session.enableFilter(filterConfiguration.getFilterName()); for (Map.Entry<String, Object> entry : filterConfiguration.getFilterParameters().entrySet()) { filter.setParameter(entry.getKey(), entry.getValue()); } } AutoEnableConfig.disableFilterEnabling(); ((EventSource) session).getActionQueue().registerProcess(filtersDisconnector); } } }
尚不清楚为何在这种情况下会破坏记录器,以及为什么仅在升级到1.4.0之后才…
我有同样的问题。我的错是由于切入点定义错误,我最终将方面应用于TransactionManager(我扩展了标准的方面)。因此,空记录器是CGLIB生成的扩展类之一。真正的bean的记录器很好地实例化了。