Spring boot - use a configurable value on a @Qualifier
I ended up adding to the main app class the two implementations autowired then define a bean for each:
@Autowired
TypeOneImpl typeOneImpl
@Bean(name = "typeOneImpl")
public InterfaceRClass getTypeOneImpl()
{
return typeOneImpl;
}
Then in the other class I defined a config field
@Value("${myClass.type}")
private String configClassType;
// the below should be defined in constructor
private final InterfaceRClass interfaceRClassElement ;
And added a setter for it with @Autowired annotation:
@Autowired
public void setMyClassType(ApplicationContext context) {
interfaceRClassElement = (InterfaceRClass) context.getBean(configClassType);
}
In configuration, the value should be typeOneImpl (typeTwoImpl is added for an additional implementation)
Spring properties (property-placeholder) autowiring
You can use @Value
:
@Value("${clientapi.url}")
public void setClientApiUrl(String clientApiUrl) {
this.clientApiUrl = clientApiUrl;
}
Related Topics
Getting the Inputstream from a Classpath Resource (Xml File)
How to Determine If a List Is Sorted in Java
Why Main() Method Is Needed in Java Main Class
Please Explain About Insertable=False and Updatable=False in Reference to the JPA @Column Annotation
What Is the Default Stack Size, Can It Grow, How Does It Work with Garbage Collection
What Is the Replacement for Javax.Activation Package in Java 9
How to Convert a 1D Array to 2D Array
Arraylist's Custom Contains Method
Simple Way to Count Character Occurrences in a String
Java Reflection: How to Get the All Getter Methods of a Java Class and Invoke Them
Create a Jtds Connection String
JSONmanagedreference VS JSONbackreference
Adding Chartpanel to Jtabbedpane Using JPAnel