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. 【Python019--函数与过程】

    一.函数与过程 1.Python只有函数没有过程 >>> def hello():    print('Hello  fishC!')>>> temp = hell ...

  2. linux --- 4. 虚拟环境

    一.虚拟环境的两种安装方式 1. virtualenv  虚拟环境 ①下载 virtualenv pip3 install -i https://pypi.tuna.tsinghua.edu.cn/s ...

  3. Jordan 块的几何

    设 $V$ 是复数域 $\mathbb{C}$ 上的 $n$ 维线性空间, $\varphi$ 是 $V$ 上的线性变换, $A\in M_n(\mathbb{C})$ 是 $\varphi$ 在某组 ...

  4. springboot项目打包部署在指定的tomcat容器中

    1.首先需要修改项目的打包方式,将package改为war <packaging>war</packaging> 2.移除spring boot web中的嵌入式tomcat ...

  5. RedHat7安装Docker

    RedHat 启动 docker报错: 错误:Error starting daemon: SELinux is not supported with the overlay2 graph drive ...

  6. 关于BOARD_SYSTEMIMAGE_PARTITION_SIZE【转】

    本文转载自:https://blog.csdn.net/ttxgz/article/details/7542380 1. 系统需要,把需要预置在系统的所有apk放在目录 device/softwinn ...

  7. P3833 [SHOI2012]魔法树

    思路 树剖板子 注意给出点的编号是从零开始的 代码 #include <cstdio> #include <algorithm> #include <cstring> ...

  8. SQL语句总结2018-11-7

    增加一条数据 insert into table (列字段1,列字段2)values(列1值,列2值) 删除一条数据 delete from table where 列名1=值1 修改一条数据 upd ...

  9. Vue学习一:{{}}html模板使用方法

    本文为博主原创,未经允许不得转载: 之前自学了vue,在项目中应用了vue,由于是第一次使用,感觉非常强大,使用也非常方便,趁有时间,总结一下vue学习过程中 各个指令的使用方法,只要掌握了vue的指 ...

  10. 阿里巴巴数据库连接池 druid配置详解

    一.背景 java程序很大一部分要操作数据库,为了提高性能操作数据库的时候,又不得不使用数据库连接池.数据库连接池有很多选择,c3p.dhcp.proxool等,druid作为一名后起之秀,凭借其出色 ...