最近学习spring,照着网上的文章自己动手练习,看了很多文章还是没有办法解决
applicationContext.xml<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans SYSTEM "spring-beans.dtd">
<beans>
<bean id="BeforeAdvice" class="com.kedacom.spring.aop.BeforeAdvice"></bean>
<bean id="AfterAdvice" class="com.kedacom.spring.aop.AfterAdvice"></bean>
<bean id="CompareInterceptor" class="com.kedacom.spring.aop.CompareInterceptor"></bean>
<bean id="StudentTagget" class="com.kedacom.spring.aop.StudentImpl"></bean>
<bean id="Student" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces">
<value>
com.kedacom.spring.aop.Student
</value>
</property>
<property name="Interceptornames">
<list>
<value>BeforeAdvice</value>
<value>AfterAdvice</value>
<value>CompareInterceptor</value>
</list>
</property>
<property name="Target">
<ref bean="studenttarget"/>
</property>
</bean>
</beans>
错误信息:log4j:WARN No appenders could be found for logger (org.springframework.beans.factory.xml.XmlBeanDefinitionReader).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'Student' defined in file [F:\myeclipse workspace\Spring_Aop\src\applicationContext.xml]: Can't resolve reference to bean 'studenttarget' while setting property 'Target'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'studenttarget' is defined: org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [BeforeAdvice,AfterAdvice,CompareInterceptor,StudentTagget,Student]; root of BeanFactory hierarchy
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'studenttarget' is defined: org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [BeforeAdvice,AfterAdvice,CompareInterceptor,StudentTagget,Student]; root of BeanFactory hierarchy
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:351)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedBeanDefinition(AbstractBeanFactory.java:640)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:147)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:176)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:105)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:916)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:727)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:336)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:147)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:271)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:312)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:82)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:67)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:58)
at com.kedacom.spring.aop.Test.main(Test.java:10)

解决方案 »

  1.   

    看了很多人说是加的jar包不对
      

  2.   

    那你就把你的加载的jar包发出来看一下。
    在 WEB-INF/lib 目录下
      

  3.   

    No bean named 'studenttarget' is defined
    bean id="StudentTagget"大小写啊大小写
      

  4.   

    No bean named 'studenttarget' is defined
    bean id="StudentTagget"大小写啊大小写
      

  5.   

    大小写改过了,加入的jar包有:
    asm-all.jar,
    cglib-nodep.jar,
    common-collecttions.jar,
    common-dbcp.jar,
    common-long.jar,
    common-loging.jar,
    common-poor.jar,
    log4j.jar,
    jta.jar,
    spring.jar
      

  6.   

    <bean id="StudentTagget" class="com.kedacom.spring.aop.StudentImpl"></bean> <property name="Target">
            <ref bean="studenttarget"/>
        </property>你确定你改了?
      

  7.   

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans SYSTEM "spring-beans.dtd">
    <beans>
    <bean id="BeforeAdvice" class="com.kedacom.spring.aop.BeforeAdvice"></bean>
    <bean id="AfterAdvice" class="com.kedacom.spring.aop.AfterAdvice"></bean>
    <bean id="CompareInterceptor" class="com.kedacom.spring.aop.CompareInterceptor"></bean>
    <bean id="StudentTagget" class="com.kedacom.spring.aop.StudentImpl"></bean>
    <bean id="Student" class="org.springframework.aop.framework.ProxyFactoryBean">
    <property name="proxyInterfaces">
    <value>
    com.kedacom.spring.aop.Student.
    </value>
    </property>
    <property name="Interceptornames">
    <list>
    <value>BeforeAdvice</value>
    <value>AfterAdvice</value>
    <value>CompareInterceptor</value>
    </list>
    </property>
    <property name="Target">
    <ref bean="StudentTagget"/>
    </property>
    </bean>
    </beans>
      

  8.   

    新的报错信息那?
    <property name="proxyInterfaces">
            <value>
                com.kedacom.spring.aop.Student.
            </value>
        </property>
    屁股后面那诡异的 . 是啥东西
      

  9.   

    这些id的都是大写开头的?那你的Service层里声明的时候呢,要保持一致
      

  10.   

    刚把  .  去了,手误造成的,楼上好眼力啊!
    log4j:WARN No appenders could be found for logger (org.springframework.beans.factory.xml.XmlBeanDefinitionReader).
    log4j:WARN Please initialize the log4j system properly.
    Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'Student' defined in file [F:\myeclipse workspace\Spring_Aop\src\applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'Interceptornames' of bean class [org.springframework.aop.framework.ProxyFactoryBean]: Bean property 'Interceptornames' is not writable or has an invalid setter method: Does the parameter type of the setter match the return type of the getter?
    org.springframework.beans.NotWritablePropertyException: Invalid property 'Interceptornames' of bean class [org.springframework.aop.framework.ProxyFactoryBean]: Bean property 'Interceptornames' is not writable or has an invalid setter method: Does the parameter type of the setter match the return type of the getter?
    at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:796)
    at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:716)
    at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:844)
    at org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperImpl.java:871)
    at org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperImpl.java:860)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:926)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:727)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:336)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:223)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:147)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:271)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:312)
    at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:82)
    at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:67)
    at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:58)
    at com.kedacom.spring.aop.Test.main(Test.java:10)
      

  11.   

    哎...这么清楚的报错信息 你自己看看呗...
     Bean property 'Interceptornames' is not writable or has an invalid setter method: Does the parameter type of the setter match the return type of the getter?get / set 函数没写
      

  12.   

    get / set 函数没写对吧你仔细看看
      

  13.   

    也许是例子本身有错,看看视频,谢谢wolf的细心回答!