从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
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)