zoukankan      html  css  js  c++  java
  • Spring-Boot:Profile简单示例

    //Resources目录下创建 application.properties
    spring.profiles.active=prod
    
    //Resources目录下创建 application-prod.properties
    book.name=spring boot prod
    package com.example.entity;
    
    import org.springframework.boot.context.properties.ConfigurationProperties;
    import org.springframework.stereotype.Component;
    
    /**
     * Created by liz19 on 2017/1/26.
     */
    @Component
    @ConfigurationProperties(prefix = "book")
    public class Book {
    
        private String name;
    
        public String getName() {
            return name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    }
    package com.example;
    
    import com.example.entity.Book;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.boot.context.properties.EnableConfigurationProperties;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    @RestController
    @SpringBootApplication
    @EnableConfigurationProperties({Book.class})
    public class DemoApplication {
    
        @Autowired
        private Book book;
    
        @RequestMapping("/")
        public Book index(){
    
            return book;
        }
    
        public static void main(String[] args) {
            SpringApplication.run(DemoApplication.class, args);
        }
    }

    1. spring.profiles.active 指定使用的profile

    2. Book为配置类, profile中的配置对Book类进行注入

    3. @ConfigurationProperties(prefix = "book") 开启配置文件管理并用前缀为book的值进行注入

  • 相关阅读:
    Cocos2d-x 使用物理引擎进行碰撞检测
    Cocos2d粒子系统二
    cocos2d(粒子效果编辑器)
    关于Cococs中的CCActionEase(下)
    关于Cococs中的CCActionEase(中)
    关于Cococs中的CCActionEase
    call()和apply() 的区别
    WebStorm 使用快捷键大全
    WebStorm 的使用(一)
    导入xlsx,文件到sqlite3数据库
  • 原文地址:https://www.cnblogs.com/MarchThree/p/6358594.html
Copyright © 2011-2022 走看看