解決 org.springframework.context.annotation.ConflictingBeanDefinitionException


Java web 項目啟動時報錯

報錯信息:

Caused by: org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'testService' for bean class [test.service.impl.TestServiceImpl] conflicts with existing, non-compatible bean definition of same name and class [test.service.impl.TestService]

 

通過搜索定位到是以下代碼片段造成的報錯。

代碼片段:

代碼1.ITestService 的實現類代碼:
@Service("testService")
public class TestServiceImpl implements ITestService {
......
}

代碼2.在Controller中使用代碼:
@Autowired
private ITestService testService;

 代碼 1 和 代碼2 中的 testService 沖突了,項目啟動時編譯器檢測到有兩個相同名稱的bean就會報錯。

解決方法:

修改代碼1和代碼2中任意一個的名字即可解決

例如:修改代碼1中的名字

1.ITestService 的實現類代碼:
@Service("testServiceImpl")
public class TestServiceImpl implements ITestService {
......
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM