resteasy invoke service inside another service

人盡茶涼 提交于 2019-12-11 16:13:21

问题


I have a services X and Y. If I want to invoke Y inside X. Is there a way to do that thru annotations. I don't want to configure a bean for X/Y, as all the other resources are Autowired for X.

Thanks!


回答1:


Spring can only inject managed instances:

@Service
public class X {

   @Resource
   private Y y;
}


@Service
public class Y {
}

If you do not like to add @Service to class Y, then you could use this (X will be the same)

@Configuration
public class AppConfig {
   @Bean
   public Y y {
      return new Y();
   }
}


来源:https://stackoverflow.com/questions/5542473/resteasy-invoke-service-inside-another-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!