Java 从@controller读取弹簧配置文件
我想将maven配置文件链接到spring配置文件。该项目是在war文件中生成的。该应用程序是部署在Weblogic服务器中的Spring应用程序,而不是SpringBoot 我有这个Java 从@controller读取弹簧配置文件,java,spring,maven,spring-mvc,Java,Spring,Maven,Spring Mvc,我想将maven配置文件链接到spring配置文件。该项目是在war文件中生成的。该应用程序是部署在Weblogic服务器中的Spring应用程序,而不是SpringBoot 我有这个pom.xml文件 <profile> <id>debug</id> <activation> <activeByDefault>true</activeByDefault> </activatio
pom.xml
文件
<profile>
<id>debug</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<spring.profiles.active>debug</spring.profiles.active>
</properties>
</profile>
..
但是activeProfiles
是空的
我使用了相同的方法得到了相同的结果
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<spring.profiles.to.activate>local</spring.profiles.to.activate>
</properties>
真的
地方的
您只是用Maven配置文件定义了spring.profiles.active
属性值。该属性可用于Maven构建,例如用于资源筛选
该值仍然必须传递给运行Spring Boot的JVM,例如,JUnit测试通常使用Maven Surefire插件运行,该插件派生JVM,如果不使用argLine
配置,则不会看到属性:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Dspring.profiles.active=${spring.profiles.active}</argLine>
</configuration>
</plugin>
</plugins>
</build>
org.apache.maven.plugins
maven surefire插件
-Dspring.profiles.active=${spring.profiles.active}
对于任何用于启动Spring Boot应用程序的Maven插件,上述情况通常都是正确的。我尝试了建议的解决方案,但结果相同:-(@carlesxuriguera您如何运行Spring Boot应用程序?请添加一个选项该应用程序是部署在Weblogic服务器中的Spring应用程序,而不是SpringBoot。@carlesxuriguera那么为什么要标记您的帖子
Spring Boot
?如果它部署为WAR,您需要将活动配置文件保存在某个地方,或者是在Weblogic中的WAR中。在您的例子中,Maven只是一个构建工具,它与运行Spring应用程序无关。
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Dspring.profiles.active=${spring.profiles.active}</argLine>
</configuration>
</plugin>
</plugins>
</build>