簡體   English   中英

"考慮在配置中定義“com.example.conferencedemo.services.SessionService”類型的 bean"

[英]Consider defining a bean of type 'com.example.conferencedemo.services.SessionService' in your configuration

我正在嘗試實現企業級,它們有像Repository<\/strong> , Service<\/strong> , ServiceImpl<\/strong>這樣的文件夾

  1. 在服務中,它們具有與方法聲明的接口

  2. 在 ServiceImpl 他們有實現服務接口的類

  3. 在存儲庫中,它們具有所有存儲庫接口

  4. BeanInjection 是一個類,我們在其中擁有所有存儲庫和服務類以及帶有@Autowired<\/strong>注釋的接口。

  5. 當我嘗試對服務類實施“@Autowired”時出現此錯誤。

  6. 試過這個沒有幫助的鏈接<\/a>

  7. 試過這個沒有幫助,但得到循環錯誤鏈接<\/a>

    控制器.java<\/strong>

     SessionService.java(接口)<\/strong>

     SessionServiceImpl.java(類)<\/strong>

     BeanInjectionService.java(類)<\/strong>

     SessionRepository.java(接口)<\/strong>

    提前致謝<\/strong>

    "

我發現使用BeanInjectionService<\/code> ,但我會回答它。

  1. 除非您在SessionServiceImpl<\/code>上添加@Service<\/code> ,否則您無法自動裝配它。<\/li>
  2. 循環依賴<\/strong>- 如果您執行第 1 步,它將創建循環依賴,因為SessionServiceImpl<\/code>需要首先創建其超類對象( BeanInjectionService<\/code> )。 但是除非找到SessionServiceImpl<\/code>的對象,否則無法創建BeanInjectionService<\/code> 。<\/li>
  3. 要打破循環依賴,您只有一種選擇。 不要擴展BeanInjectionService<\/code> 。 相反, SessionRepository<\/code>直接自動連接到SessionServiceImpl<\/code>中。<\/li><\/ol>
     @Service public class SessionServiceImpl implements SessionService { @Autowired private SessionRepository sessionRepository; @Override public List<Session> findAll(){ return sessionRepository.findAll(); } }<\/code><\/pre>"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM