No bean named 'accountService' available
错误信息
"D:\Intellij\IntelliJ IDEA 2019.2.3\jbr\bin\java.exe" "-javaagent:D:\Intellij\IntelliJ IDEA 2019.2.3\lib\idea_rt.jar=54888:D:\Intellij\IntelliJ IDEA 2019.2.3\bin" -Dfile.encoding=UTF-8 -classpath D:\Intellij\spring-ioc\spring-aop\spring-aop-xml\spring-aop-zj\target\test-classes;D:\Intellij\spring-ioc\spring-aop\spring-aop-xml\spring-aop-zj\target\classes;C:\Users\cm\.m2\repository\org\aspectj\aspectjweaver\1.8.9\aspectjweaver-1.8.9.jar;C:\Users\cm\.m2\repository\mysql\mysql-connector-java\5.1.40\mysql-connector-java-5.1.40.jar;C:\Users\cm\.m2\repository\org\springframework\spring-context\5.0.2.RELEASE\spring-context-5.0.2.RELEASE.jar;C:\Users\cm\.m2\repository\org\springframework\spring-aop\5.0.2.RELEASE\spring-aop-5.0.2.RELEASE.jar;C:\Users\cm\.m2\repository\org\springframework\spring-beans\5.0.2.RELEASE\spring-beans-5.0.2.RELEASE.jar;C:\Users\cm\.m2\repository\org\springframework\spring-core\5.0.2.RELEASE\spring-core-5.0.2.RELEASE.jar;C:\Users\cm\.m2\repository\org\springframework\spring-jcl\5.0.2.RELEASE\spring-jcl-5.0.2.RELEASE.jar;C:\Users\cm\.m2\repository\org\springframework\spring-expression\5.0.2.RELEASE\spring-expression-5.0.2.RELEASE.jar;C:\Users\cm\.m2\repository\commons-dbutils\commons-dbutils\1.4\commons-dbutils-1.4.jar;C:\Users\cm\.m2\repository\c3p0\c3p0\0.9.1.2\c3p0-0.9.1.2.jar;C:\Users\cm\.m2\repository\junit\junit\4.10\junit-4.10.jar;C:\Users\cm\.m2\repository\org\hamcrest\hamcrest-core\1.1\hamcrest-core-1.1.jar AOPTest
7月 20, 2021 6:37:53 下午 org.springframework.context.support.AbstractApplicationContext prepareRefresh
信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@15615099: startup date [Tue Jul 20 18:37:53 CST 2021]; root of context hierarchy
7月 20, 2021 6:37:53 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [bean.xml]
Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'accountService' available
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:687)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1205)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1085)
at AOPTest.main(AOPTest.java:11)
Process finished with exit code 1
在已经配置@Service("/accountService")注解的情况下,测试类获取对象出错No bean named ‘accountService’ available
解决方案
将Service注解**@Service("/accountService")中的 " / " 删除,正确的注解为@Service(“accountService”)**如图所示
修改后bug消失