resteasy invoke service inside another service

2019-09-04 13:13发布

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条回答
We Are One
2楼-- · 2019-09-04 13:19

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();
   }
}
查看更多
登录 后发表回答