《Springboot极简教程》SpringBoot配置文件PropertySourcesPlaceholderConfigurer

简介: package com.restfiddle.config;import org.springframework.context.annotation.
package com.restfiddle.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;

/**
 * Created by santoshm1 on 04/06/14.
 *
 * Adds support for runtime property files. Run with -Dspring.profiles.active={production,default,development,test} defaults to development.
 *
 */

@Configuration
@PropertySource(value={"classpath:common.properties"})
public class PropertyConfig {

    public PropertyConfig() {}

    @Bean
    public static PropertySourcesPlaceholderConfigurer myPropertySourcesPlaceholderConfigurer() {
    return new PropertySourcesPlaceholderConfigurer();
    }

    /**
     * Properties to support the 'production' mode of operation.
     */
    @Configuration
    @Profile("production")
    @PropertySource(value={"classpath:env-production.properties"})
    static class Production {
    // Define additional beans for this profile here
    }

    /**
     * Properties to support the 'test' mode of operation.
     */
    @Configuration
    @Profile({ "devlopment", "default" })
    @PropertySource(value={"classpath:env-development.properties"})
    static class Dev {
    }

    /**
     * Properties to support the 'test' mode of operation.
     */
    @Configuration
    @Profile("test")
    @PropertySource(value={"classpath:env-test.properties"})
    static class Test {
    }
}

相关文章
|
前端开发 Java Linux
《Linux篇》02.超详细SpringBoot项目部署教程(附脚本自动部署)(三)
《Linux篇》02.超详细SpringBoot项目部署教程(附脚本自动部署)(三)
1358 0
《Linux篇》02.超详细SpringBoot项目部署教程(附脚本自动部署)(三)
|
JSON Java 数据格式
【SpringBoot】配置文件的加载与属性值的绑定
【SpringBoot】配置文件的加载与属性值的绑定
【SpringBoot】配置文件的加载与属性值的绑定
|
Java
有关Springboot的配置文件动态配置环境问题【亲测】
有关Springboot的配置文件动态配置环境问题【亲测】
260 0
SpringBoot配置文件的优先级
SpringBoot配置文件的优先级
|
Java Maven
springboot读取yml配置文件
springboot读取yml配置文件
232 0
|
Java 测试技术 Spring
SpringBoot是怎么实现在配置文件的随机数的?
随机数的使用你是不是经常用到?我们在进行运行`SpringBoot`单元测试时一般不会指定应用程序启动时的`端口号`,可以在`application.properties`文件内配置`server.port`的值为`${random.int(10000)}`,代表了随机使用`0~10000`的端口号。
|
Java 测试技术 Spring
SpringBoot如何加载jar包外面的配置文件?
虽然现在springboot提供了多环境的支持,但是通常修改一下配置文件,都需要重新打包。 在开发springboot框架集成时,我遇到一个问题,就是如何让@PropertySource能够“扫描”和加载jar包外面的properties文件。
|
SpringCloudAlibaba Java Nacos
SpringBoot使用spring.config.import多种方式导入配置文件
`SpringBoot`从2.4.x版本开始支持了导入文件的方式来加载配置参数,与`spring.config.additional-location`不同的是不用提前设置而且支持导入的文件类型相对来说要丰富很多。
|
存储 安全 Java
SpringBoot整合SpringSecurity完整教程
SpringBoot整合SpringSecurity完整教程
SpringBoot整合SpringSecurity完整教程
|
监控 安全 Java
《SpringBoot启动流程三》:两万+字图文带你debug源码分析SpringApplication准备阶段(含配置文件加载时机、日志系统初始化时机)
《SpringBoot启动流程三》:两万+字图文带你debug源码分析SpringApplication准备阶段(含配置文件加载时机、日志系统初始化时机)
257 0
《SpringBoot启动流程三》:两万+字图文带你debug源码分析SpringApplication准备阶段(含配置文件加载时机、日志系统初始化时机)