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 ...
随机推荐
- 入职两个月,WPF开发感想
1 .新工作,新开始 2.WPF初次接触以及学习MVVM开发模式 3.后台数据操作,ORACLE 存储过程(边做边学) 4.总结 4.1工作开发中的小问题 ,遇到的坑: 4.2 解决的问题,学校到的 ...
- 【CYH-02】noip2018数论模拟赛:比赛通知栏
鉴于公开赛有时可能无法更改比赛描述呢... 所以我们准备在这里(和团队宣言里)发布一些比赛公告. 请及时关注
- Docker笔记(六):容器管理
原文地址:http://blog.jboost.cn/2019/07/21/docker-6.html 容器是Docker中的另一核心概念,在Docker中,应用的运行都是在容器内进行的,容器则基于镜 ...
- [PTA] 数据结构与算法题目集 6-12 二叉搜索树的操作集
唯一比较需要思考的删除操作: 被删除节点有三种情况: 1.叶节点,直接删除 2.只有一个子节点,将子节点替换为该节点,删除该节点. 3.有两个子节点,从右分支中找到最小节点,将其值赋给被删除节点的位置 ...
- .Net微信网页开发之使用微信JS-SDK自定义微信分享内容
第一步.微信JS-SDK的使用步骤,配置信息的生成获取讲解: 关于JS-SDK的使用步骤和timestamp(时间戳),nonceStr(随机串),signature(签名),access_token ...
- linux 使用git
linux下使用git管理代码 环境:centos7.2 : 工具:xshell 1.安装git,命令如下: #yum install git 2.设置用户名和邮箱,命令如下: #git c ...
- JavaScript Boolean(逻辑)对象
Boolean(逻辑)对象用于将非逻辑值转换为逻辑值(true 或者 false). 实例 检查逻辑值 检查逻辑对象是 true 还是 false. 完整的 Boolean 对象参考手册 我们提供 J ...
- handlerAdapter与方法调用(参数的解析)
前提:当找到handler以后,那么就要让handler发挥作用,这个时候handlerAdapter就派上用场了 这里面比较复杂就是requestMappingHandlerAdapter了,其他的 ...
- Java 第四章
switch选择结构 语法:switch(表达式){ case 常量 1: //代码块1: break: case 常量 2: //代码块2: break: ...... default ...
- 【MySQL】添加多个字段
MySQL 遇到了添加多个字段的问题,尝试了几次,搞定了,记录下. 示例代码如下: alter table ad_data add ( exposure_count bigint(20) defaul ...