@Configuration
public class MyConfig {
@Bean(name = "myObj")
public MyObj getMyObj() {
return new MyObj();
}
}
I have this MyConfig object with @Configuration Spring annotation.
My question is that how I can retrieve the bean programmatically (in a regular class)?
for example, the code snippet looks like this.
Thanks in advance.
public class Foo {
public Foo(){
// get MyObj bean here
}
}
public class Var {
public void varMethod(){
Foo foo = new Foo();
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…