【发布时间】:2019-07-25 09:47:36
【问题描述】:
我有 Spring Boot 应用程序。
我正在尝试从 tomcat 位置访问 application.properties 文件。
我点击了这个链接:How to externalize application.properties in Tomcat webserver for Spring?
MortgageLoanApiApplication
package com.Mortgage.MortgageLoanAPI;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class MortgageLoanApiApplication {
public static void main(String[] args) {
System.setProperty("spring.config.name", "application");
SpringApplication.run(MortgageLoanApiApplication.class, args);
}
}
ServletInitializer
package com.Mortgage.MortgageLoanAPI;
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("spring.config.name: application");
}
}
C:\Program Files\Apache Software Foundation\Apache Tomcat 8.0.9\bin\setenv.sh
export spring_config_location=C:/Program Files/Apache Software Foundation/Apache Tomcat 8.0.9/conf/
C:\Program Files\Apache Software Foundation\Apache Tomcat 8.0.9\conf\application.properties
spring.datasource.url=jdbc:mysql://localhost:3306/mortgage_loan
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=root
但是当我运行应用程序或构建应用程序时。它显示错误,因为它没有找到数据库连接。
2019-03-04 10:53:28.318 INFO 2872 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-03-04 10:53:28.325 ERROR 2872 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
让我知道如何解决这个问题。或者如果有任何其他方式可以访问 使用 Spring Boot 从 tomcat 位置获取属性文件。
【问题讨论】:
标签: java spring-boot tomcat properties application.properties