Having the following class structure:
public abstract class A {
String someProperty = "property"
public abstract void doSomething();
}
@Service
public class Aa extends A {
@Override
public abstract void doSomething() {
System.out.println("I did");
}
}
@Service
public class Ab extends A {
@Override
public abstract void doSomething() {
System.out.println("I did something else");
}
}
I need a way to tell Spring which A
concrete class to Autowire
in my Foo service, based on a property in a properties file.
@Service
public class Foo {
@Autowire
private A assignMeAConcreteClass;
}
And in my properties
file I have this:
should-Aa-be-used: {true, false}
Remove the @Service
annotation, instead write a @Bean
-annotated method in a configuration class that reads the properties, and returns the appropriate A
instance.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments