简体   繁体   English

Spring Boot找不到特定于配置文件的属性文件

[英]Spring Boot can't find profile-specific properties files

I am following Spring documentation to use profile specific property files for my SpringBoot app. 我正在遵循Spring文档为SpringBoot应用程序使用特定于配置文件的属性文件。 I have 2 property files under src/main/resources : datasource.properties for local development and datasource-prod.properties for server datasource config. 我有以下的属性文件src/main/resourcesdatasource.properties为地方发展和datasource-prod.properties用于服务器的数据源配置。

This is my DataSourceConfiguration.java config class : 这是我的DataSourceConfiguration.java配置类:

@Configuration
@PropertySource("classpath:datasource-{profile}.properties")
@Slf4j
public class DataSourceConfiguration {

    @Value("${flad.datasource.driver}")
    private String dataSourceDriverClassName;
    @Value("${flad.datasource.url}")
    private String dataSourceUrl;
    @Value("${flad.datasource.username}")
    private String dataSourceUsername;
    @Value("${flad.datasource.password}")
    private String dataSourcePassword;

    @Bean
    public DataSource getDataBase(){
        log.info("Datasource URL = {}", dataSourceUrl);
        return DataSourceBuilder
                .create()
                .driverClassName(dataSourceDriverClassName)
                .url(dataSourceUrl)
                .username(dataSourceUsername)
                .password(dataSourcePassword)
                .build();
    }
}

When I launch my SpringBootApplication main class I get the following error whether I use -Dspring.profiles.active=prod or not : 当我启动SpringBootApplication主类时,无论是否使用-Dspring.profiles.active=prod我都会收到以下错误:

17:05:49.008 [restartedMain] ERROR org.springframework.boot.SpringApplication - Application run failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [fr.payet.flad.core.config.CoreConfig]; nested exception is java.io.FileNotFoundException: class path resource [datasource-{profile}.properties] cannot be opened because it does not exist

我找到的解决方案是重命名我的属性文件datasource-local.propertiesdatasource-prod.properties ,以这种方式使用@PropertySource @PropertySource("classpath:datasource-${profile}.properties")并在启动SpringBoot时使用我使用-Dprofile=local作为VM选项的应用程序

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 依赖于特定于配置文件的属性的 Spring Boot 属性 - Spring Boot properties that depend on profile-specific properties 使用 Maven 配置构建 Spring Boot Profile-specific Properties - Spring Boot Profile-specific Properties build using Maven Configuration Spring Boot构建变体与gradle的特定于配置文件的属性 - Spring boot build variants Profile-specific properties with gradle 在使用PropertiesLauncher启动的Spring-boot(特定于配置文件)应用程序中发出覆盖应用程序属性的问题 - Issue overriding application properties in Spring-boot (profile-specific) application launched with PropertiesLauncher 替换 spring 配置文件特定属性文件中的属性占位符 - Replace property placeholders in spring profile-specific properties file 使用来自多个 application.properties 文件的单个特定于配置文件的属性文件 - Use single profile-specific property file from multiple application.properties files 如何制作特定于配置文件的 bootstrap.yml? - How can I make a profile-specific bootstrap.yml? 使用配置文件运行spring boot jar文件-错误找不到属性文件 - Run spring boot jar file with profiles - error can't find properties files 在 Spring 引导中配置特定的自定义属性文件 - Profile specific custom property files in Spring boot Spring Boot应用程序(特定于配置文件).properties返回null - spring boot application(profile specific).properties returns null
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM