[英]Add property to application.properties for "mvnw clean package"?
While debugging in STS, I need property xxx.yyy.zzz to either be / or not there at all.在 STS 中调试时,我需要属性 xxx.yyy.zzz 要么是/要么根本不存在。 However, when deploying to Tomcat via mvnw clean package, I need to add xxx.yyy.zzz=/myApp但是,通过mvnw clean package部署到Tomcat时,需要添加xxx.yyy.zzz=/myApp
I saw a SO overflow post that says you just need to do:我看到一个 SO 溢出的帖子说你只需要做:
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<xxx.yyy.zzz>/myApp</xxx.yyy.zzz>
</systemPropertyVariables>
</configuration>
</plugin>
But that doesn't work.但这不起作用。 I've been reading up on profiles, but I think that is overkill for my needs, I don't want to maintain multiple copies of the properties, I just want to override that one property.我一直在阅读配置文件,但我认为这对我的需求来说太过分了,我不想维护属性的多个副本,我只想覆盖那个属性。 Is there a way to do the profiles where you just have values to override?有没有办法在您只有要覆盖的值的情况下执行配置文件?
This is for a spring boot app.这是用于 Spring Boot 应用程序的。
EDIT:编辑:
Based on Khalil's suggestion, I am trying profiles.根据 Khalil 的建议,我正在尝试配置文件。
1) I added application-tomcat.properties 1) 我添加了 application-tomcat.properties
2) In pom.xml, I added: 2)在pom.xml中,我添加了:
<profiles>
<profile>
<id>tomcat</id>
<properties>
<spring.properties.active>tomcat</spring.properties.active>
</properties>
</profile>
</profiles>
3) I did mvnw clean package -P tomcat 3)我做了 mvnw clean package -P tomcat
No errors, and the deployment went fine, but its not reading the property.没有错误,部署顺利,但它没有读取属性。
what's wrong with this solution?这个解决方案有什么问题?
application-root.properties应用程序-root.properties
xxx.yyy.zzz=/ xxx.yyy.zzz=/
application-not-root.properties application-not-root.properties
bla bla
@Profile("root")
public String xxYY(){
return yourVar;
}
@Profile("Notroot")
public String xxYY(){
return "";
}
if (your condition){
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.getEnvironment().setActiveProfiles("root or no root");
}
or even this if you're talking about Tomcat:甚至这个,如果你在谈论 Tomcat:
if (your condition)
servletContext.setInitParameter("spring.profiles.active", "root or no root");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.