场景:在普通类或枚举类中(非Controller、Service类),需要调用service,查数据库等;
示例代码:
public class XXX {
private static testService test = null;
@Component
public static class GetService{
@Autowired
private TestService testService;
@PostConstruct
private void getTestService(){
XXX.test = testService;
}
}
}