我在我的 spring boot 应用程序中使用 spring 配置文件配置环境变量。我在那里做了配置
我的界面是
public interface EnvConfiguration {
String getServerUrl();
}
我的开发配置是
@Component
public class DevelopmentConfig implements EnvConfiguration{
@Value("${DEV}")
private String serverUrl;
@Override
public String getServerUrl(){
return serverUrl;
}
}
@Configuration
@Profile("dev")
public class DevelopmentProfile {
@Bean
public EnvConfiguration getDevelopmentConfig(){
return new DevelopmentConfig();
}
}
和我为生产环境配置的一样
@Component
public class ProductionConfig implements EnvConfiguration {
@Value("${PROD}")
private String serverUrl;
@Override
public String getServerUrl(){
return serverUrl;
}
}
@Configuration
@Profile("prod")
public class ProductionProfile {
@Bean
public EnvConfiguration getProductionConfig(){
return new ProductionConfig();
}
}
现在我使用运行配置->agruments 在 eclipse 中配置环境变量
-Dspring.profiles.active="dev"
现在,当我尝试运行我的应用程序时,出现错误:
expected single matching bean but found 2: productionConfig,developmentConfig
所以请帮助我在那里我错过了什么?
提前致谢!