spring boot ----> spring boot 和spring的联系
1、自动配置的实现是基于spring 4.0的条件化配置,这是spring 4.0的新特性。比如,定义一个类A,它实现Condition接口,覆盖condition接口的match()方法,那么该类变成一个条件类。我们可以在某个方法上使用这个类时,在方法上使用注解@Conditional(A.class),表明当A类的条件成立时,方法才会被执行。
public class A implements Condition{
@Override
public boolean match(ConditionContext context, AnnotationTypeMetadata metadata) {
//do something....
return true;
}
}
@Conditional(A.class)
public void oneService (){}
2、自定义配置属性:为不同的环境配置不同的属性,spring boot的实现基于spring 3.1的Profile配置,Profile是一种条件化配置。spring boot通过注解@Profile("???")和配置文件application.properties的形式来实现。我们需要在配置文件中配置这么一行:spring.profile.active=???,这行配置能激活Profile,那么就可以使用注解了@Profile的配置类。
另外spring boot中还可以通过命名配置文件的名字来区分不同的环境以达到为不同的环境配置不同的属性。首先需要遵循命名规则:application-{profileName}.properties,如果使用的是yml文件,类似的规则是:application-{profileName}.yml;使用yml文件也可以把profile配置在一个文件内,用一组三个连字符(---)分隔开,分成不同的部分,像这样:
x:
y:
z: xyz
---
spring:
profiles: dev
x2:
y2:
z2: x2y2z2
---
spring:
profiles: prod
x3:
y3:
z3: x3y3z3
spring boot ----> spring boot 和spring的联系的更多相关文章
- spring cloud教程之使用spring boot创建一个应用
<7天学会spring cloud>第一天,熟悉spring boot,并使用spring boot创建一个应用. Spring Boot是Spring团队推出的新框架,它所使用的核心技术 ...
- 【Spring】关于Boot应用中集成Spring Security你必须了解的那些事
Spring Security Spring Security是Spring社区的一个顶级项目,也是Spring Boot官方推荐使用的Security框架.除了常规的Authentication和A ...
- [转]Spring Boot——2分钟构建spring web mvc REST风格HelloWorld
Spring Boot——2分钟构建spring web mvc REST风格HelloWorld http://projects.spring.io/spring-boot/ http://spri ...
- Springboot(一):使用Intellij中的Spring Initializr来快速构建Spring Boot工程
使用Intellij中的Spring Initializr来快速构建Spring Boot工程 New---Project 可以看到图所示的创建功能窗口.其中Initial Service Url指向 ...
- spring boot 系列之四:spring boot 整合JPA
上一篇我们讲了spring boot 整合JdbcTemplate来进行数据的持久化, 这篇我们来说下怎么通过spring boot 整合JPA来实现数据的持久化. 一.代码实现 修改pom,引入依赖 ...
- 一起来学spring Cloud | 第一章:spring Cloud 与Spring Boot
目前大家都在说微服务,其实微服务不是一个名字,是一个架构的概念,大家现在使用的基于RPC框架(dubbo.thrift等)架构其实也能算作一种微服务架构. 目前越来越多的公司开始使用微服务架构,所以在 ...
- spring Boot 入门--为什么用spring boot
为什么用spring boot 回答这个问题不得不说下spring 假设你受命用Spring开发一个简单的Hello World Web应用程序.你该做什么? 我能想到一些 基本的需要. 一个项目 ...
- Spring Boot (五)Spring Data JPA 操作 MySQL 8
一.Spring Data JPA 介绍 JPA(Java Persistence API)Java持久化API,是 Java 持久化的标准规范,Hibernate是持久化规范的技术实现,而Sprin ...
- (转)Spring Boot 2 (八):Spring Boot 集成 Memcached
http://www.ityouknow.com/springboot/2018/09/01/spring-boot-memcached.html Memcached 介绍 Memcached 是一个 ...
- spring boot 2.0.3+spring cloud (Finchley)3、声明式调用Feign
Feign受Retrofix.JAXRS-2.0和WebSocket影响,采用了声明式API接口的风格,将Java Http客户端绑定到他的内部.Feign的首要目标是将Java Http客户端调用过 ...
随机推荐
- FireMonkey 源码学习(6)
(6)GetGlyph和GetBaseline TFontGlyphManager是一个抽象类,在不同平台上的实现是不同的,以Windows为例,在FMX.FontGlyphs.Win.pas文件中定 ...
- Array数组集合的排序
/* ######### ############ ############# ## ########### ### ###### ##### ### ####### #### ### ####### ...
- SpringBoot 使用Sharding-JDBC进行分库分表及其分布式ID的生成
为解决关系型数据库面对海量数据由于数据量过大而导致的性能问题时,将数据进行分片是行之有效的解决方案,而将集中于单一节点的数据拆分并分别存储到多个数据库或表,称为分库分表. 分库可以有效分散高并发量,分 ...
- 题解——UVA11997 K Smallest Sums
题面 背景 输入 输出 翻译(渣自翻) 给定K个包含K个数字的表,要求将其能产生的\( k^{k} \)个值中最小的K个输出出来 题解 k路归并问题的经典问题 可以转化为二路归并问题求解 考虑A[], ...
- 常用的 Linux 命令
列出文件列表:ls [参数 -a -l]创建目录和移除目录:mkdir rmdir用于显示文件后几行内容:tail打包:tar -xvf打包并压缩:tar -zcvf查找字符串:grep显示当前所在目 ...
- communication
Always consider the challenge as a chance. Basic principles: Know your audience. Know your purpose. ...
- spring 配置ibatis和自动分页
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.spr ...
- 异步编程- async和await
使用目的 避免阻塞主线程 提高程序响应能力 C#中使用 C# 中的 Async 和 Await 关键字是异步编程的核心. 疑惑 The async and await keywords don't c ...
- 理解 Redis(1) - Redis 简介
Redis 的含义 全称: REmote DIctionary Server 远程词典服务器 由于支持 string, list, set, ordered set, hash 等多重数据结构, 因此 ...
- sticky-footer的三种解决方案
在网页设计中,Sticky footers设计是最古老和最常见的效果之一,大多数人都曾经经历过.它可以概括如下:如果页面内容不够长的时候,页脚块粘贴在视窗底部:如果内容足够长时,页脚块会被内容向下推送 ...