spring基于注解的普通类怎么调用@Services注解的service方法

来源:互联网 发布:mac webstorm git使用 编辑:程序博客网 时间:2024/09/21 08:56
spring基于注解的普通类怎么调用@Services注解的service方法,需要一些先决条件:1、如果你想用@autowired,那么这个类本身也应该是在spring的管理下的,即你的UserLogUtil也要标注为一个component(或Service),这样spring才知道要注入依赖;2、或者,不标注为@Component的话,此时不能通过@autowired来注入依赖,只能通过ApplicationContext来取得标注为Service的类:UserLogService service = ApplicationContext.getBean(UserLogService.class);

0 0