Spring Profiles:ActiveProfilesResolver的简单示例?

我在做什么?
我有一个应用程序,我想在不同的环境中测试 – 开发,登台等

我所做的?
我正在使用maven cargo插件来部署应用程序战以运行集成测试。

我需要的?
我需要根据货物设置的环境变量来测试spring.profiles.active

   tomcat7x  development   

为什么?
这样我就可以在我的Integration Test @ActiveProfiles("development")删除硬编码,测试可以从环境变量推断出什么是活动的配置文件


– 我发现使用profile的Spring集成测试提到了使用ActiveProfilesResolver
– 我试图找到如何使用它,但找不到任何资源
我正在寻找有关如何使用ActiveProfilesResolver指导/建议

尝试这个。 我从不同的地方学习并创造了以下内容。 这个对我有用

 public class SpringActiveProfileResolver implements ActiveProfilesResolver { @Override public String[] resolve(final Class aClass) { final String activeProfile = System.getProperty("spring.profiles.active"); return new String[] { activeProfile == null ? "integration" : activeProfile }; } } 

在你的测试课上做这个

 @ActiveProfiles(resolver = SpringActiveProfileResolver.class) public class IT1DataSetup { ...... }