Вы можете попробовать использовать @ConditionalOnProperty
:
@Configuration
public class MyInterfaceConfiguration {
@Bean
@ConditionalOnProperty(value = "my.interfacte.impl", havingValue="firstImpl")
public MyInterface firstImpl(){
return new FirstImpl();
}
@Bean
@ConditionalOnProperty(value = "my.interfacte.impl", havingValue="secondImpl")
public MyInterface secondImpl(){
return new SecondImpl();
}
}
, и когда вы обновите вашу собственность в application.properties
с помощью привода / обновления до:
my.interfacte.impl=firstImpl
, вы получитеFirstImpl
экземпляр. Если у вас есть:
my.interfacte.impl=secondImpl
, у вас будет SecondImpl
.