学习用xml方式管理事务时,控制台报错
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [applicationContext.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0': Cannot create inner bean '(inner bean)#d278d2b' of type [org.springframework.aop.aspectj.AspectJExpressionPointcut] while setting bean property 'pointcut'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#d278d2b': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.springframework.aop.aspectj.AspectJExpressionPointcut] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@2437c6dc]
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [applicationContext.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0': Cannot create inner bean '(inner bean)#d278d2b' of type [org.springframework.aop.aspectj.AspectJExpressionPointcut] while setting bean property 'pointcut'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#d278d2b': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.springframework.aop.aspectj.AspectJExpressionPointcut] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@2437c6dc]
xml代码如下:
<!--事务配置-->
<!--事务管理器对象-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!--事务增强-->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
<!--aop织入-->
<aop:config>
<aop:advisor advice-ref="txAdvice" pointcut="execution(* com.msdn.service.Impl.*.*(..))"></aop:advisor>
</aop:config>
不加此段代码不报错,后但单独把aop:config注释掉后不报错。经查,原来是pom文件中没有导入aop坐标,导入后功能正常
<!--aop织入-->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.13</version>
</dependency>
反观异常信息,nested(嵌套的),aop等字样也表示aop报错