'How to Autowire Spring Bean for Enum in Java
How can I avoid creating new objects by using spring configuration @Bean for Enums
Example in below enum E how can I avoid new A() and new B() object creation using spring configuration Beans.
public enum E {
FIRST(new A()), // How to avoid creating new objects using Spring beans
SECOND(new B());
private final I i;
E(I arg){
this.i = arg;
}
public static someMethod(){};
}
public interface I{
int method(){}
}
public class A implements I {
@Override
public int method(){}
}
public class B implements I {
@Override
public int method(){}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
