谁能让它运行起来——Spring AOP无法运行

我的配置文件如下:
<?xml version="1.0" encoding="UTF-8"?>
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&amp;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

启动的时候报错:
信息: Initializing Spring root WebApplicationContext
log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.
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)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
2013-2-27 17:37:21 org.apache.catalina.core.StandardContext start
严重: Error listenerStart
2013-2-27 17:37:21 org.apache.catalina.core.StandardContext start
严重: Context [/wett] startup failed due to previous errors

如果不加入:
/aop:aspectj-autoproxy便能运行,,为什么呢。请大侠们看看,,我需要用到aop...

1个回答

如果用的是SpringMVC ,在加载dispatcherServlet这个servlet的时候,也有一个配置文件-servlet.xml,将AOP 配置 /aop:aspectj-autoproxy 放在上面的xml文件中,试试。

dts228
Ri 呵呵。。谢谢哈。。居然我重启了下eclipse,, 它就好了。。我真是无语啊。。整了半天。。
大约 7 年之前 回复
fatherican
飞猪it 不是,我的意思是说,在配置DispatcherServlet的时候,该DispatcherServlet应该会加载一个配置文件,该配置文件的名字默认情况下是<servlet-name>-servlet.xml,这个文件中定义了,视图的配置,上传文件的配置等。可以把</aop:aspectj-autoproxy>也放在这个配置文件中。
大约 7 年之前 回复
dts228
Ri 感谢哈,我们用的spring mvn,但是我们的全部是注入,不需要servlet.xml.
大约 7 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问