Spring AOP无法执行

Ri 2013-02-27 05:49:23
请大侠们帮忙瞅瞅,为嘛无法运行起来呢:
配置如下:
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd"
>

<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
<context:annotation-config/>
<context:component-scan base-package="com.len"> </context:component-scan>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceXmlLocation" value="WEB-INF/jpa.xml"/>
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="database" value="MYSQL" />
<property name="showSql" value="false" />
</bean>
</property>
</bean>

<bean id="entityManagerAdvisor" class="org.springframework.aop.support.DefaultPointcutAdvisor">
<property name="advice">
<bean class="org.springframework.orm.jpa.JpaInterceptor" autowire="byName" />
</property>
</bean>

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://127.0.0.1:3306/apkbak?useUnicode=true&characterEncoding=utf8"/>
<property name="username" value="root"/>
<property name="password" value=""/>
<property name="initialSize" value="20"/>
<property name="maxActive" value="100"/>
<property name="maxIdle" value="20"/>
<property name="minIdle" value="0"/>
<property name="testOnBorrow"><value>true</value></property>
<property name="validationQuery"><value>SELECT 1 FROM DUAL</value></property>
</bean>

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<aop:aspectj-autoproxy proxy-target-class="true"></aop:aspectj-autoproxy>
</beans>

启动爆错:
2013-2-27 17:37:21 org.apache.catalina.core.StandardContext listenerStart
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0': Bean with name 'org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0' has been injected into other beans [org.springframework.transaction.config.internalTransactionAdvisor] in its raw version as part of a circular reference, but has eventually been wrapped. This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'getBeanNamesOfType' with the 'allowEagerInit' flag turned off, for example.
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:546)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4205)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4704)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)


如果去掉:
<aop:aspectj-autoproxy proxy-target-class="true"></aop:aspectj-autoproxy>则正常,为什么呢?
如果去掉事务配置,保留aop也能正常运行!!
我需要用2个啊。
...全文
112 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
丨深水蓝丨 2013-02-28
  • 打赏
  • 举报
回复
亲,把你的 <aop:aspectj-autoproxy proxy-target-class="true"></aop:aspectj-autoproxy>拿出来配置, 另外加上:

<!-- 配置事务特性 -->
	<tx:advice id="txAdvice" transaction-manager="transactionManager">
		<tx:attributes>
			 <tx:method name="exists" read-only="true" /> 
		<tx:method name="save*" propagation="REQUIRED" />   
       <tx:method name="add*" propagation="REQUIRED" />   
        <tx:method name="create*" propagation="REQUIRED" />   
        <tx:method name="insert*" propagation="REQUIRED" />   
        <tx:method name="update*" propagation="REQUIRED" />   
        <tx:method name="merge*" propagation="REQUIRED" />   
        <tx:method name="del*" propagation="REQUIRED" />   
        <tx:method name="remove*" propagation="REQUIRED" />   
        <tx:method name="put*" propagation="REQUIRED" />   
        <tx:method name="use*" propagation="REQUIRED"/>   
        <!-- hibernate4必须配置为开启事务 否则 getCurrentSession()获取不到    -->
        <tx:method name="get*" propagation="REQUIRED" />   
        <tx:method name="count*" propagation="REQUIRED" read-only="true" />   
        <tx:method name="find*" propagation="REQUIRED" read-only="true" />   
        <tx:method name="list*" propagation="REQUIRED" read-only="true" />  
         <tx:method name="*" propagation="REQUIRED" /> 
			
		</tx:attributes>
	</tx:advice>

	
	<!-- 配置哪些类的方法进行事务管理 -->
	<aop:config proxy-target-class="true">
		<aop:pointcut id="bussinessService" expression="execution(* com.shop.service..impl.*.*(..))" />
		<aop:advisor pointcut-ref="bussinessService" advice-ref="txAdvice" />
	</aop:config>
com.shop.service..impl.*.*(..) 改成你自己的.

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧