there is a utility class that needs to reference bean
@Component
class FooUtils implements InitializingBean {
private static Foo foo;
private static Bar bar;
@Autowired
private void foo(Foo foo) {
MyFactory.foo = foo;
}
@Override
public void afterPropertiesSet() throws Exception {
bar = new Bar(foo, ...);
}
public static MyObj create(int param1, int param2, int param3) {
if (foo == null) { thrown new Exception(); }
return new MyObj(foo.baz(param1, param2), bar, param3);
}
}
want to create bean with the utility class above
@Configuration
@DependsOn("fooUtils") // <-- work, newbeaninit
class Config {
@Bean
public MyObj myObjBean() {
return FooUtils.create(1, 2, 3); // <-- fooUtilsautowired
}
}
@Service
class MyService {
@Autowired
private MyObj myObj;
}