栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

在Tomcat中为Spring Boot应用程序访问externalize application.properties?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在Tomcat中为Spring Boot应用程序访问externalize application.properties?

从tomcat目录访问application.properties文件。那么我们需要遵循以下步骤

需要在中添加插件

pom.xml
。这意味着部署后它将忽略工作区的application.properties文件

<!-- Added the below plugin to not include the application.properties inside the war --><plugin>    <artifactId>maven-war-plugin</artifactId>    <version>2.6</version>    <configuration>        <failOnMissingWebXml>false</failOnMissingWebXml>        <packagingExcludes> **/application.properties/        </packagingExcludes>    </configuration></plugin>

需要将application.properties文件复制到tomcat目录

lib
位置。那么我们需要更改
ServletInitializer.java
文件。

"classpath:mortgage-api/"
意味着我们需要
mortgage-api
在tomcat
lib文件夹中创建一个名称为的文件夹,并将application.properties文件复制到该位置。检查代码注释。

import java.util.Properties;import org.springframework.boot.builder.SpringApplicationBuilder;import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;public class ServletInitializer extends SpringBootServletInitializer {    @Override    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {        return application.sources(MortgageLoanApiApplication.class).properties(loadproperties());    }        private Properties loadproperties() {          Properties props = new Properties();          props.put("spring.config.location", "classpath:mortgage-api/");          return props;       }}

然后

mvn clean
,然后建立war文件
mvn install



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/635637.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号