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的联系的更多相关文章

  1. spring cloud教程之使用spring boot创建一个应用

    <7天学会spring cloud>第一天,熟悉spring boot,并使用spring boot创建一个应用. Spring Boot是Spring团队推出的新框架,它所使用的核心技术 ...

  2. 【Spring】关于Boot应用中集成Spring Security你必须了解的那些事

    Spring Security Spring Security是Spring社区的一个顶级项目,也是Spring Boot官方推荐使用的Security框架.除了常规的Authentication和A ...

  3. [转]Spring Boot——2分钟构建spring web mvc REST风格HelloWorld

    Spring Boot——2分钟构建spring web mvc REST风格HelloWorld http://projects.spring.io/spring-boot/ http://spri ...

  4. Springboot(一):使用Intellij中的Spring Initializr来快速构建Spring Boot工程

    使用Intellij中的Spring Initializr来快速构建Spring Boot工程 New---Project 可以看到图所示的创建功能窗口.其中Initial Service Url指向 ...

  5. spring boot 系列之四:spring boot 整合JPA

    上一篇我们讲了spring boot 整合JdbcTemplate来进行数据的持久化, 这篇我们来说下怎么通过spring boot 整合JPA来实现数据的持久化. 一.代码实现 修改pom,引入依赖 ...

  6. 一起来学spring Cloud | 第一章:spring Cloud 与Spring Boot

    目前大家都在说微服务,其实微服务不是一个名字,是一个架构的概念,大家现在使用的基于RPC框架(dubbo.thrift等)架构其实也能算作一种微服务架构. 目前越来越多的公司开始使用微服务架构,所以在 ...

  7. spring Boot 入门--为什么用spring boot

    为什么用spring boot 回答这个问题不得不说下spring 假设你受命用Spring开发一个简单的Hello World Web应用程序.你该做什么? 我能想到一些 基本的需要.  一个项目 ...

  8. Spring Boot (五)Spring Data JPA 操作 MySQL 8

    一.Spring Data JPA 介绍 JPA(Java Persistence API)Java持久化API,是 Java 持久化的标准规范,Hibernate是持久化规范的技术实现,而Sprin ...

  9. (转)Spring Boot 2 (八):Spring Boot 集成 Memcached

    http://www.ityouknow.com/springboot/2018/09/01/spring-boot-memcached.html Memcached 介绍 Memcached 是一个 ...

  10. spring boot 2.0.3+spring cloud (Finchley)3、声明式调用Feign

    Feign受Retrofix.JAXRS-2.0和WebSocket影响,采用了声明式API接口的风格,将Java Http客户端绑定到他的内部.Feign的首要目标是将Java Http客户端调用过 ...

随机推荐

  1. 20145308 《网络对抗》 MAL_免杀原理及实践 学习总结

    20145308 <网络对抗> MAL_免杀原理及实践 学习总结 实践内容 (1)理解免杀技术原理 (2)正确使用msf编码器,veil-evasion,自己利用shellcode编程等免 ...

  2. oracle单行函数 之 字符函数

    Upper(字符串 / 列):将输入的字符串变成大写 Lower(字符串 / 列):将输入的字符串变成小写 Initcap(字符串 / 列):开头首字母大写 Length(字符串 / 列):字符串长度 ...

  3. 【AI】微软人工智能学习笔记(二)

    微软Azure机器学习服务 01|机器学习概述 首先上一张图, 这个图里面的大神是谁我也不清楚反正,但是看起来这句话说得很有哲理就贴出来了. 所以在人工智能领域下面的这个机器学习,到底是一个什么样的概 ...

  4. to do list_hadoop

    1.页面翻译 2.UI优化 vue.js reactive.js 3.Hadoop生态学习 Spark.Kafka.Druid……

  5. error: could not create '/System/Library/Frameworks/Python.framework/Versions/2.7/share': Operation not permitted

    参考: Python pip安装模块报错 Mac升级到EI Captain之后pip install 无法使用问题 error: could not create '/System/Library/F ...

  6. 1、Python模块和包(0602)

    模块.异常.运行环境.mysqldb 模块: 顶层文件:作为整个文件的程序入口,就是负责去调用其他文件中的代码来实现程序流程功能的,称为顶层程序文件, 模块文件1 模块文件2 python模块 1.可 ...

  7. HDU 1298 T9(字典树+dfs)

    http://acm.hdu.edu.cn/showproblem.php?pid=1298 题意:模拟手机9键,给出每个单词的使用频率.现在给出按键的顺序,问每次按键后首字是什么(也就是要概率最大的 ...

  8. Java方法中捕获多个异常的处理机制

    /** * @author wangyunhan * @throws Exception */ public static void main(String[] argßs) throws Excep ...

  9. js之鼠标随动后面跟随事件(类似于长龙跟着跑)

    <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...

  10. Python深入:Distutils发布Python模块--转载

    https://blog.csdn.net/gqtcgq/article/details/49255995 Distutils可以用来在Python环境中构建和安装额外的模块.新的模块可以是纯Pyth ...