简体   繁体   English

"考虑在配置中定义“com.example.conferencedemo.services.SessionService”类型的 bean"

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

I am trying to implement as of enterprise level, there they have folders like Repository<\/strong> , Service<\/strong> , ServiceImpl<\/strong>我正在尝试实现企业级,它们有像Repository<\/strong> , Service<\/strong> , ServiceImpl<\/strong>这样的文件夹

  1. In Services they have interface with method declaration在服务中,它们具有与方法声明的接口

    <\/li>

  2. In ServiceImpl they have class implementing the interface of services在 ServiceImpl 他们有实现服务接口的类

    <\/li>

  3. In Repository they have all Repository interfaces在存储库中,它们具有所有存储库接口

    <\/li>

  4. BeanInjection is a class where we have all repositories and service classes and interfaces with @Autowired<\/strong> annotation. BeanInjection 是一个类,我们在其中拥有所有存储库和服务类以及带有@Autowired<\/strong>注释的接口。

    <\/li>

  5. When I tried to implement "@Autowired" to service class getting this Error.当我尝试对服务类实施“@Autowired”时出现此错误。

    <\/li>

  6. Tried this no help link<\/a>试过这个没有帮助的链接<\/a>

    <\/li>

  7. Tried this no help but getting loop error link<\/a>试过这个没有帮助,但得到循环错误链接<\/a>

    <\/li><\/ol>

    Controller.java<\/strong>控制器.java<\/strong>

     public class SessionController extends BeanInjectionService { @GetMapping public ResponseEntity<List<Session>> list(){ LOGGER.info("Request received to view the sessions"); List<Session> sessions = sessionService.findAll(); LOGGER.info("Successfully fetched all the sessions"); return new ResponseEntity<>(sessions, HttpStatus.OK); }<\/code><\/pre>

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

     public interface SessionService { List<Session> findAll(); }<\/code><\/pre>

    SessionServiceImpl.java(Class)<\/strong> SessionServiceImpl.java(类)<\/strong>

     public class SessionServiceImpl extends BeanInjectionService implements SessionService { @Override public List<Session> findAll(){ return sessionRepository.findAll(); }<\/code><\/pre>

    BeanInjectionService.java(Class)<\/strong> BeanInjectionService.java(类)<\/strong>

     public class BeanInjectionService { @Autowired public SessionRepository sessionRepository; **\/\/ Error Showing here while starting application \/\/ Consider defining a bean of type 'com.example.conferencedemo.services.SessionService' in your configuration.** @Autowired public SessionService sessionService; @Autowired public SpeakerRepository speakerRepository; @Autowired public SpeakerService speakerService; }<\/code><\/pre>

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

     public interface SessionRepository extends JpaRepository<Session,Long> { }<\/code><\/pre>

    Thanks in advance<\/strong>提前致谢<\/strong>

    "

I find using BeanInjectionService<\/code> a little weird, but I'll answer around it.我发现使用BeanInjectionService<\/code> ,但我会回答它。

  1. Unless you add @Service<\/code> on SessionServiceImpl<\/code> , you can't autowire it.除非您在SessionServiceImpl<\/code>上添加@Service<\/code> ,否则您无法自动装配它。<\/li>
  2. Circular dependency<\/strong> - If you do step 1, it will create a circular dependency because SessionServiceImpl<\/code> needs its superclass object( BeanInjectionService<\/code> ) to be created first.循环依赖<\/strong>- 如果您执行第 1 步,它将创建循环依赖,因为SessionServiceImpl<\/code>需要首先创建其超类对象( BeanInjectionService<\/code> )。 But BeanInjectionService<\/code> cannot be created unless it finds an object of SessionServiceImpl<\/code> .但是除非找到SessionServiceImpl<\/code>的对象,否则无法创建BeanInjectionService<\/code> 。<\/li>
  3. To break the circular dependency, you have only one option.要打破循环依赖,您只有一种选择。 Don't extend BeanInjectionService<\/code> .不要扩展BeanInjectionService<\/code> 。 Rather, autowire SessionRepository<\/code> directly into SessionServiceImpl<\/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.

相关问题 春季启动:考虑在配置中定义类型为“ com.repository.services.interfacename”的bean - Spring boot: Consider defining a bean of type 'com.repository.services.interfacename' in your configuration 考虑在您的配置中定义类型为“com.example.conexion.repository.ClienteRepository”的 bean - Consider defining a bean of type 'com.example.conexion.repository.ClienteRepository' in your configuration 考虑在你的配置中定义一个 &#39;com.example.filter.FilterDao&#39; 类型的 bean - Consider defining a bean of type 'com.example.filter.FilterDao' in your configuration 考虑在您的配置中定义“com.example.transaction.manager.properties.TransacationManagerProperties”类型的 bean - Consider defining a bean of type 'com.example.transaction.manager.properties.TransacationManagerProperties' in your configuration 考虑在您的配置中定义类型为“com.repository.UserRepository”的 bean - Consider defining a bean of type 'com.repository.UserRepository' in your configuration 考虑在您的配置中定义一个“com.example.amazonsync.Service.IAmazonUtilService”类型的 bean - Consider defining a bean of type 'com.example.amazonsync.Service.IAmazonUtilService' in your configuration 考虑在配置中定义类型为&#39;com.ensat.services.ProductService&#39;的bean - Consider defining a bean of type 'com.ensat.services.ProductService' in your configuration 考虑在你的配置中定义一个 'com.example.demo.Commands$DefaultIO' 类型的 bean - Consider defining a bean of type 'com.example.demo.Commands$DefaultIO' in your configuration 考虑在您的配置中定义类型为“ com.face.ImageRepository”的bean? - Consider defining a bean of type 'com.face.ImageRepository' in your configuration? 考虑在配置问题中定义类型的 bean - Consider defining a bean of type in your configuration issue
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM