spring扫描出现Annotation-specified bean name 'userService' for bean class [com.test.service.UserService]

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/HaleyLiu123/article/details/75091406

现象描述:

spring中配置 <context:component-scan base-package="com." />对服务自动扫描

public interface PersonService {}

@Service("personService")

public class PersonServiceImpl implements PersonService {}

启动报错,

Annotation-specified bean name 'personService' for bean class [com.test.service.PersonService] conflicts with existing


分析原因: 出现这个错误主要是你的spring里面的bean名字重复了。


解决方法:

(1)如果只需要扫描impl指定目录下的包,不扫其他重复bean所在包可解决问题

spring中配置 <context:component-scan base-package="com...impl.*" /> 也能解决问题。


(2)去掉相同的bean名称,解决根本问题


展开阅读全文

No bean class specified on bean definition

06-26

rnrnrn rn rn rn rn rn rn com.mysql.jdbc.Driverrn rn rn rn rn jdbc:mysql://localhost:3306/db_managerrn rn rn rn rn rootrn rn rn rn 1234rn rn rn rn rn 30rn rn rn rn rn 3rn rn rn rn rn 3rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn com/eportal/ORM/category.hbm.xmlrn rn rn rn rn rn rn rn org.hibernate.dialect.MySQLDialectrn truern 100rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn PROPAGATION_REQUIRED,readOnlyrn PROPAGATION_REQUIRED,readOnlyrn PROPAGATION_REQUIRED,readOnlyrn PROPAGATION_REQUIRED,readOnlyrn PROPAGATION_REQUIRED,readOnlyrn PROPAGATION_REQUIRED rn rn rn rn rn rn rn rn rn rn rn rn rn categoryServicern rn rn rn rn rn rn truern rn rn rn rn rn rn transactionInterceptorrn rn rn rn rn rn rn rn rnrn rn rn rn rn rn rnrnrnrnrn错误如下:rnorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator' defined in class path resource [applicationContext.xml]: Instantiation of bean failed; nested exception is java.lang.IllegalStateException: No bean class specified on bean definitionrn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:883)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:839)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)rn at java.security.AccessController.doPrivileged(Native Method)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)rn at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)rn at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)rn at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)rn at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729)rn at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381)rn at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)rn at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83)rn at testMerchandise.WireBean.getBean(WireBean.java:13)rn at testMerchandise.TestORM.testAppContxt(TestORM.java:310)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rn at java.lang.reflect.Method.invoke(Method.java:597)rn at junit.framework.TestCase.runTest(TestCase.java:154)rn at junit.framework.TestCase.runBare(TestCase.java:127)rn at junit.framework.TestResult$1.protect(TestResult.java:106)rn at junit.framework.TestResult.runProtected(TestResult.java:124)rn at junit.framework.TestResult.run(TestResult.java:109)rn at junit.framework.TestCase.run(TestCase.java:118)rn at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)rn at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)rnCaused by: java.lang.IllegalStateException: No bean class specified on bean definitionrn at org.springframework.beans.factory.support.AbstractBeanDefinition.getBeanClass(AbstractBeanDefinition.java:348)rn at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:49)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:877)rn ... 33 morernrn 论坛

没有更多推荐了,返回首页