【问题标题】:Application.properties location when tomcat deploysTomcat部署时的Application.properties位置
【发布时间】:2019-09-24 21:44:06
【问题描述】:

我在默认资源中有一个带有application.properties 的war 文件。我想,在 Tomcat 上部署时,将这些属性放入外部文件夹,如 /webapps/example,而不是 /webapps/namewar

我可以配置我的 Maven 或做一些事情来实现吗?

非常感谢。

【问题讨论】:

  • 在Springboot中,在你的主类中,你可以使用注解@PropertySources({ @PropertySource(value="classpath:application.properties") , ignoreResourceNotFound = true) })来定义加载application.properties的位置,这是默认的classpath,改成你想要的就行了跨度>
  • 也可以添加多个@PropertySource注解
  • 嗨!我不想这样做,我想在部署 tomcat 时将这些属性移动到外部文件夹,就像使用 .war 的根文件夹一样
  • 我认为你不能在 Maven 上进行任何配置,因为它只会在构建战争时出现,而不是在爆炸和部署战争时出现。你可以做的是编写一个脚本来在tomcat上部署你的war,它会在exploding war后复制你的应用程序属性,然后启动tomcat服务器。

标签: java maven spring-boot tomcat


【解决方案1】:

您可以使用 maven-resources-plugin 的 copy-resources 目标将文件从源代码树复制到某个目录。您需要在 pom.xml 中添加如下内容:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>3.1.0</version>
        <executions>
          <execution>
            <id>copy-resources</id>
            <!-- you may want to choose another phase -->
            <!-- see https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference -->
            <phase>validate</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <!-- outputDirectory can be absolute or relative to ${basedir} -->
              <outputDirectory>/webapps/example</outputDirectory>
              <resources>          
                <resource>
                  <directory>src/main/resources</directory><!-- or whereever your application.properties reside -->
                  <includes>
                    <include>application.properties</include>
                  </includes>
                </resource>
              </resources>              
            </configuration>            
          </execution>
        </executions>
      </plugin>
    </plugins>
    ...
  </build>
  ...
</project>

【讨论】:

  • 当我点击“Maven - 安装”时正在复制,但我想做完全相同的事情,但是当 tomcat 开始一些战争时。我可以吗?
  • 如何启动 Tomcat?
  • 我从控制台开始
  • 那也许你想写一个脚本,先复制application.properties文件,然后启动服务器?
  • 是的,我认为应该是有效的。
猜你喜欢
  • 2019-10-04
  • 1970-01-01
  • 2020-06-19
  • 2019-12-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多