Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从@controller读取弹簧配置文件_Java_Spring_Maven_Spring Mvc - Fatal编程技术网

Java 从@controller读取弹簧配置文件

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

我想将maven配置文件链接到spring配置文件。该项目是在war文件中生成的。该应用程序是部署在Weblogic服务器中的Spring应用程序,而不是SpringBoot

我有这个
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>