Starters

可以创建自己的Starter,但名字格式不能是 spring-boot-starter-*,而是 *-spring-boot-starter。类似Maven插件的规则。
 

自动配置

@Import 和 @ComponentScan 类似;
@EnableAutoConfiguration 和 @SpringBootApplication 类似;---注意,只能使用一次,建议用在primary @Configuration class上。
 
注意,自动配置永远是第二位的,一旦你配置自己的东西,那自动配置的就会被覆盖。
查看自动配置都配置了什么,以及为什么,启动应用的时候加上 --debug即可。
禁用特定的自动配置:
import org.springframework.boot.autoconfigure.*;
import org.springframework.boot.autoconfigure.jdbc.*;
import org.springframework.context.annotation.*;
@Configuration
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
public class MyConfiguration {
}
如果class不在classpath中,可以使用 excludeName,然后使用全路径即可。
 

@SpringBootApplication

@SpringBootApplication 等同于默认的属性的 @Configuration@EnableAutoConfiguration and @ComponentScan。 
-- 注意,@ComponentScan 不能凭空使用。

类型安全的Configuration Properties

这里的意思是说,通过Java类来确保类型安全,但值还是要在YAML中提供!!

做为配置文件的对象类

@ConfigurationProperties(prefix="connection")
public class ConnectionProperties {
private String username;
private InetAddress remoteAddress;
// ... getters and setters
}
那么,@Value("${property}")  和@ConfigurationProperties 的区别? 暂略。
注意:通过 @ConfigurationProperties 类进行的properties设置,需要在 @Configuration 类上开启 @EnableConfigurationProperties 注解才行,
而且,需要手动添加 @ConfigurationProperties 类,
如下:
用@Configuration注解该类,等价 与XML中配置beans;用@Bean标注方法等价于XML中配置bean。
@Configuration
@EnableConfigurationProperties(ConnectionProperties.class)
public class MyConfiguration {
}
需要注意的是, @ConfigurationProperties 类对应的bean有一个约定好的名字: <prefix>-<fqn> 。fqn是full qualified name。
前面的例子,对应的名字是: connection-com.example.ConnectionProperties ,这里假定它在包 com.example 中。
但是,@ConfigurationProperties 类对应的bean还有一个默认的名字!!!只是,不建议在environment之外使用而已。

由于 @EnableConfigurationProperties 注解 会被自动应用到项目中,所以,只要确保 @ConfigurationProperties 类 是一个bean(即@Component),就会被自动添加到 Environment 。如下:

@Component //确保是一个bean即可!
@ConfigurationProperties(prefix="connection")
public class ConnectionProperties {
// ... getters and setters of username and remoteAddress, and so on
}

Profiles

@Profile 可以用于 @Component 或 @Configuration 。
 

spring boot 注解说明的更多相关文章

  1. Spring boot注解(annotation)含义详解

    Spring boot注解(annotation)含义详解 @Service用于标注业务层组件@Controller用于标注控制层组件(如struts中的action)@Repository用于标注数 ...

  2. Spring boot 注解简单备忘

    Spring boot 注解简单备忘 1.定义注解 package com.space.aspect.anno;import java.lang.annotation.*; /** * 定义系统日志注 ...

  3. 73. Spring Boot注解(annotation)列表【从零开始学Spring Boot】

    [从零开始学习Spirng Boot-常见异常汇总] 针对于Spring Boot提供的注解,如果没有好好研究一下的话,那么想应用自如Spring Boot的话,还是有点困难的,所以我们这小节,说说S ...

  4. Spring Boot 注解之ObjectProvider源码追踪

    最近依旧在学习阅读Spring Boot的源代码,在此过程中涉及到很多在日常项目中比较少见的功能特性,对此深入研究一下,也挺有意思,这也是阅读源码的魅力之一.这里写成文章,分享给大家. 自动配置中的O ...

  5. Spring Boot注解大全,一键收藏了!

    本文首发于微信公众号[猿灯塔],转载引用请说明出处 今天是猿灯塔“365天原创计划”第5天. 今天呢!灯塔君跟大家讲: Spring Boot注解大全 一.注解(annotations)列表 @Spr ...

  6. (转)spring boot注解 --@EnableAsync 异步调用

    原文:http://www.cnblogs.com/azhqiang/p/5609615.html EnableAsync注解的意思是可以异步执行,就是开启多线程的意思.可以标注在方法.类上. @Co ...

  7. spring boot注解 --@EnableAsync 异步调用

    EnableAsync注解的意思是可以异步执行,就是开启多线程的意思.可以标注在方法.类上. @Component public class Task { @Async public void doT ...

  8. spring boot注解之@Scheduled定时任务实现

    java实现定时任务一般使用timer,或者使用quartz组件.现在在spring boot提供了更加方便的实现方式. spring boot已经集成了定时任务.使用@Secheduled注解. @ ...

  9. Spring Boot 注解的使用

    Spring Boot 优于Spring mvc ,SSM,SSH 的一个亮点就是他使用了好多的注解. 1. @Autowired 这个注解的作用是将其他的类,接口引入,类似于之前的类的初始化等,用这 ...

  10. Spring Boot 注解详解

    一.注解(annotations)列表 @SpringBootApplication:包含了@ComponentScan.@Configuration和@EnableAutoConfiguration ...

随机推荐

  1. JXM 监控tomcat 7(含代码

    1.在tomcat的server.xml中加入: <Listener className="org.apache.catalina.mbeans.JmxRemoteLifecycleL ...

  2. checkBox1_CheckedChanged(object sender, EventArgs e)和checkBox1_CheckStateChanged(object sender, EventArgs e)不同

    using System; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms ...

  3. java 字符串—数字常用处理

    // 判断一个字符串是否都为数字 public boolean isDigit(String strNum) { return strNum.matches("[0-9]{1,}" ...

  4. error C2143: 语法错误 : 缺少“;”(在“类型”的前面)

    C编程老是遇到这个问题: 错误 error C2143: 语法错误 : 缺少“;”(在“类型”的前面) d:\kinectproject\ceshiglad\ceshiglad\shili.c ces ...

  5. BZOJ2830 & 洛谷3830:[SHOI2012]随机树——题解

    https://www.luogu.org/problemnew/show/P3830#sub   <-题面看这里~ https://www.lydsy.com/JudgeOnline/prob ...

  6. BZOJ3994:[SDOI2015]约数个数和——题解

    http://www.lydsy.com/JudgeOnline/problem.php?id=3994 https://www.luogu.org/problemnew/show/P3327#sub ...

  7. srtlen实现以及与sizeof的比较

    这里仅为个人整理,大部分来自百科  一.strlen函数 strlen所作的仅仅是一个计数器的工作,它从内存的某个位置(可以是字符串开头,中间某个位置,甚至是某个不确定的内存区域)开始扫描,直到碰到第 ...

  8. [Leetcode] gas station 气站

    There are N gas stations along a circular route, where the amount of gas at station i isgas[i]. You ...

  9. AOJ.866 飞越原野 (三维BFS)

    AOJ.866 飞越原野 (三维BFS) 题意分析 点我挑战题目 相比于普通的BFS,要多一维来记录当前剩余的体力.而且还要额外的一层循环来处理,飞过的路程. 代码总览 #include <io ...

  10. 关于EK Dicnic

    笔记--最大流  $EK$ $Dinic$ $EK$: 运用反向边可以给当前图一次反悔的机会,就是其实现在的增广路并不是最优的,然后就$bfs$找增广路即可 $Dicnic$: 我们发现其实每一次先$ ...