2015-06-19 144 views
4

我一直在阅读很多内容,但找不到解决方案,告诉我如何在@activeprofiles注释中嵌入maven配置文件。有没有可能?在spring boot @activeprofile注释中配置maven配置文件

我试图解决的问题,以获得H2和飞行开始之前,我的测试执行哪些没有发生。该配置在pom.xml中的maven配置文件中被解析。 当测试在teamcity中运行时,它会选择maven配置文件并执行,但是作为独立程序,他们无法找到H2和flyway的配置,并且无法启动。

回答

8

...找不到解决方案,告诉我如何在@activeprofiles注释中嵌入maven 配置文件。

你的意思是基于Maven的轮廓活泉水配置文件,如果是的话,你可以像配置,以便在你的pom.xml:

<profiles> 
    <profile> 
    <id>mvnprofile</id> 
    <properties> 
     <spring.profiles.active>springprofile</spring.profiles.active> 
    </properties> 
    <dependencies> 
     <dependency> 
     </dependency> 
    </dependencies> 
    </profile> 
    ... 
</profiles> 

在您的测试类配置它应该运行概况上..

@Runwith(..) 
@SpringApplicationConfiguration(...) 
@ActiveProfiles("springprofile") 
public class YourTest { ... } 

对于轮廓特定属性,创建另外一个application-springprofile.propertiesapplication.properties,春天开机就会先加载application.properties然后加载应用程序springpr ofile.properties - 覆盖之前由application.properties配置的任何属性。

最后,设置maven的配置文件与-P标志

$mvn test -P mvnprofile 
+0

谢谢,我一定会尽力this..it是非常有益的。 – worrynerd

相关问题