Is there some way to use @Autowired
with static fields. If not, are there some other ways to do this?
Init your autowired component in @PostConstruct method
@Component
public class TestClass {
private static AutowiredTypeComponent component;
@Autowired
private AutowiredTypeComponent autowiredComponent;
@PostConstruct
private void init() {
component = this.autowiredComponent;
}
public static void testMethod() {
component.callTestMethod();
}
}