我正在运行SpringBoot2.1.0
我想将properties.yml ties.yml文件放在webapp目录的外部。
我在tomcat文件夹中创建了一个新的setenv.sh:
export spring_config_additional-location=/path/to/file/db-properties.yml我把文件db-properties.yml . and放在那条路上。
spring:
datasource:
username: username
url: jdbc:oracle:thin:@192.168.122.2:1521:xe
password: password但是我发现了一个错误:
***************************
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有人能帮忙吗?
发布于 2021-11-10 02:57:07
我能够通过在spring引导的主类中重写下面的方法来解决同样的问题。
/**
* For External Properties
*/
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder springApplicationBuilder) {
logger.info("\nLoading properties as configured...\n");
return springApplicationBuilder.sources(MainApplication.class).properties(getProperties());
}
static Properties getProperties() {
Properties props = new Properties();
props.put(YourConstantsFile.SPRING_CONFIG_LOCATION,
"file:///xxxx/xxxx/xxx/xxx.yml");
return props;
}
This will serve the purpose when you deploy the application as a war as well.
Along with this, for locally running I included the below snippet too.
@PropertySources({ @PropertySource(value = "classpath:application.properties"),
@PropertySource(value = "file://${your.custom.file}", ignoreResourceNotFound = false)
})
@EnableTransactionManagement
@SpringBootApplication
public class MainApplication extends SpringBootServletInitializer{}
Application.properties.
server-home=${catalina.home}/anyfolder/
your.custom.file=${server-home}/xxx.ymlhttps://stackoverflow.com/questions/69159389
复制相似问题