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的值进行注入
Spring-Boot:Profile简单示例的更多相关文章
- spring boot thymeleaf简单示例
说实话,用起来很难受,但是人家官方推荐,咱得学 如果打成jar,这个就合适了,jsp需要容器支持 引入依赖 <dependency> <groupId>org.springfr ...
- Spring Boot项目简单上手+swagger配置+项目发布(可能是史上最详细的)
Spring Boot项目简单上手+swagger配置 1.项目实践 项目结构图 项目整体分为四部分:1.source code 2.sql-mapper 3.application.properti ...
- Spring boot 注解简单备忘
Spring boot 注解简单备忘 1.定义注解 package com.space.aspect.anno;import java.lang.annotation.*; /** * 定义系统日志注 ...
- Spring Boot Mybatis简单使用
Spring Boot Mybatis简单使用 步骤说明 build.gradle:依赖添加 application.properties:配置添加 代码编写 测试 build.gradle:依赖添加 ...
- 【译】Spring 4 @Profile注解示例
前言 译文链接:http://websystique.com/spring/spring-profile-example/ 本文将探索Spring中的@Profile注解,可以实现不同环境(开发.测试 ...
- 从.Net到Java学习第五篇——Spring Boot &&Profile &&Swagger2
从.Net到Java学习系列目录 刚学java不久,我有个疑问,为何用到的各种java开源jar包许多都是阿里巴巴的开源项目,为何几乎很少见百度和腾讯?不是说好的BAT吗? Spring Boot 的 ...
- Spring Boot - Profile配置
Profile是什么 Profile我也找不出合适的中文来定义,简单来说,Profile就是Spring Boot可以对不同环境或者指令来读取不同的配置文件. Profile使用 假如有开发.测试.生 ...
- Spring Boot 最简单整合Shiro+JWT方式
简介 目前RESTful大多都采用JWT来做授权校验,在Spring Boot 中可以采用Shiro和JWT来做简单的权限以及认证验证,在和Spring Boot集成的过程中碰到了不少坑.便结合自身以 ...
- spring boot一个简单用户管理DEMO
概述 该Demo旨在部署一个简单spring boot工程,包含数据编辑和查看功能 POM配置 <?xml version="1.0" encoding="UTF- ...
- spring boot actuator 简单使用
spring boot admin + spring boot actuator + erueka 微服务监控 简单的spring boot actuator 使用 POM <dependenc ...
随机推荐
- Excel催化剂开源第50波-Excel与PowerBIDeskTop互通互联之第四篇
答应过的全盘分享,也必承诺到底,此篇PowerBI功能分享的最后一篇,讲述如何导出数据模型的元数据,笔者定义其为模型的数据字典. 此篇对应功能实现出自:第6波-导出PowerbiDesktop模型数据 ...
- storm入门demo
一.storm入门demo的介绍 storm的入门helloworld有2种方式,一种是本地的,另一种是远程. 本地实现: 本地写好demo之后,不用搭建storm集群,下载storm的相关jar包即 ...
- MyBatis Generator Example.Criteria 查询条件复制
背景: 我们在开发中使用MyBatis Generator生成的 XxxExample查询时,咋添加 or 查询时候,可能两个 Example.Criteria 对象的条件存在交集,即多个查询条件是相 ...
- C++多小球非对心弹性碰撞(HGE引擎)
程序是一个月前完成的,之前一直没正儿八经的来整理下这个程序,感觉比较简单,不过即使简单的东西也要跟大家分享下. 源码下载:http://download.csdn.net/detail/y851716 ...
- ubuntu环境下测试cache大小并校验
Cache存储器:电脑中为高速缓冲存储器,是位于CPU和主存储器DRAM(Dynamic Random Access Memory)之间,规模较小,但速度很高的存储器,通常由SRAM(Static R ...
- DAO模型 架构
这是项目的架构 dao层下面有一个平级的包 impl //dao层 访问数据库. GradeDAOImpl 他继承了BaseDAO 实现了IGradeDAO接口 public class Gra ...
- Java多线程笔记总结
1.线程的三种创建方式 对比三种方式: 通过继承Thread类实现 通过实现Runnable接口 实现Callable接口 第1种方式无法继承其他类,第2,3种可以继承其他类: 第2,3种方式多线程可 ...
- HTML5-新增语义化结构标签
总结目录结构: 1.简洁的DOCTYPE声明 2.新的布局结构标签 header,article,section,aside,footer 3.新的其它常用标签: nav,hgroup,figure, ...
- netty源码解解析(4.0)-16 ChannelHandler概览
本章开始分析ChannelHandler实现代码.ChannelHandler是netty为开发者提供的实现定制业务的主要接口,开发者在使用netty时,最主要的工作就是实现自己的ChannelHan ...
- flask 异步celery使用
在开发过程中,耗时长,超时的任务经常发生,比如:获取后端某个大文件数据超时.需要后端计算任务超时,等等, 此时我们就会很自然的想到异步方式,根据需要完成的任务创建一个task_id, 由前端来监听该任 ...