SpringBoot常用配置简介

1. SpringBoot中几个常用的配置的简单介绍

  • 一个简单的Spring.factories

     # Bootstrap components
    org.springframework.cloud.bootstrap.BootstrapConfiguration=\
    org.springframework.cloud.config.server.bootstrap.ConfigServerBootstrapConfiguration # Application listeners
    org.springframework.context.ApplicationListener=\
    org.springframework.cloud.config.server.bootstrap.ConfigServerBootstrapApplicationListener
    # Autoconfiguration
    org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
    org.springframework.cloud.config.server.config.EncryptionAutoConfiguration,\
    org.springframework.cloud.config.server.config.SingleEncryptorAutoConfiguration
  • BootstrapConfiguration简介

    Spring.factories中的配置项, org.springframework.cloud.bootstrap.BootstrapConfiguration,会在Spring启动之前的准备上下文阶段将其加入到容器中。我们在介绍 @Configuration配置解析一文中曾详细解释Configuration中的解析。BootstrapConfiguration是在刷新(refresh)阶段将class作为预选的配置类@Configuration注入到容器中的,在@Configuration配置解析阶段会解析此class。

  • 加载BootstrapConfiguration配置的类

List<String> names = SpringFactoriesLoader
.loadFactoryNames(BootstrapConfiguration.class, classLoader);
for (String name : StringUtils.commaDelimitedListToStringArray(
environment.getProperty("spring.cloud.bootstrap.sources", ""))) {
names.add(name);
}
// TODO: is it possible or sensible to share a ResourceLoader?
SpringApplicationBuilder builder = new SpringApplicationBuilder()
.profiles(environment.getActiveProfiles()).bannerMode(Mode.OFF)
.environment(bootstrapEnvironment)
.properties("spring.application.name:" + configName)
.registerShutdownHook(false).logStartupInfo(false).web(false);
List<Class<?>> sources = new ArrayList<>();
for (String name : names) {
Class<?> cls = ClassUtils.resolveClassName(name, null);
try {
cls.getDeclaredAnnotations();
}
catch (Exception e) {
continue;
}
sources.add(cls);
}
builder.sources(sources.toArray(new Class[sources.size()]));
AnnotationAwareOrderComparator.sort(sources);
final ConfigurableApplicationContext context = builder.run();
  • 加载BootstrapConfiguration配置的类
private void prepareContext(ConfigurableApplicationContext context,ConfigurableEnvironment environment, SpringApplicationRunListeners listeners,ApplicationArguments applicationArguments, Banner printedBanner) {
context.setEnvironment(environment);
postProcessApplicationContext(context);
applyInitializers(context);
listeners.contextPrepared(context);
if (this.logStartupInfo) {
logStartupInfo(context.getParent() == null);
logStartupProfileInfo(context);
}
// Add boot specific singleton beans
context.getBeanFactory().registerSingleton("springApplicationArguments",
applicationArguments);
if (printedBanner != null) {
context.getBeanFactory().registerSingleton("springBootBanner", printedBanner);
} // Load the sources
Set<Object> sources = getSources();//获取需要加载的class源
Assert.notEmpty(sources, "Sources must not be empty");
load(context, sources.toArray(new Object[sources.size()]));//加载class
listeners.contextLoaded(context);
}
  • ApplicationListener简介

    org.springframework.context.ApplicationListener会在SpringBoot中几个典型事件产生后调用onApplicationEvent方法。详见Spring事件发布系统

  • Autoconfiguration简介

    org.springframework.boot.autoconfigure.EnableAutoConfiguration是SpringBoot中最常见配置,用于自动配置。只要有@EnableAutoConfiguration注解,该配置的所有类都会自动加载到Spring容器中。

SpringBoot常用配置简介的更多相关文章

  1. [转]logback常用配置简介

    logback是一套日志框架,由log4j的优化版,由同一个作者开发,在速度和性能上都超过其他日志框架,再结合slf4j,已成为当前最流行的日志框架. Logback最常用就是在classpath定义 ...

  2. SpringBoot常用配置,引入外部配置文件信息,热加载

    SpringBoot的配置文件格式 yml规范 SpringBoot的配置文件支持properties和yml,甚至还支持json. 更推荐使用yml文件格式: yml文件,会根据换行和缩进帮助咱们管 ...

  3. SpringBoot常用配置

    前言:springboot集成了主流的第三方框架,但是需要使用springboot那一套配置方式.但是我这里只列举了非常非常常用的,可以看已发的几篇博客,慢慢会补充.当然官方文档里也有相应的配置,可惜 ...

  4. ActiveMQ (二) 常用配置简介

    ActiveMQ的主要配置文件 ActiveMQ的一些常用的属性很多可以在对应的配置文件中进行配置的.比如访问web console的管理端的端口,用户名密码,连接MQ时的用户名和密码,持久化设置,是 ...

  5. SpringBoot 常用配置 静态资源访问配置/内置tomcat虚拟文件映射路径

    Springboot 再模板引擎中引入Js等文件,出现服务器拒绝访问的错误,需要配置过滤器 静态资源访问配置 @Configuration @EnableWebMvc public class Sta ...

  6. 【转】logback 常用配置详解(序)logback 简介

    原创文章,转载请指明出处:http://aub.iteye.com/blog/1101222, 尊重他人即尊重自己 详细整理了logback常用配置, 不是官网手册的翻译版,而是使用总结,旨在更快更透 ...

  7. logback常用配置详解及logback简介

    logback 简介(一) Ceki Gülcü在Java日志领域世界知名.他创造了Log4J ,这个最早的Java日志框架即便在JRE内置日志功能的竞争下仍然非常流行.随后他又着手实现SLF4J 这 ...

  8. SpringBoot阿里巴巴Fastjson的一些常用配置

    SpringBoot阿里巴巴Fastjson的一些常用配置 @Bean public HttpMessageConverters fastJsonHttpMessageConverters() { F ...

  9. SpringBoot 入门篇(二) SpringBoot常用注解以及自动配置

    一.SpringBoot常用注解二.SpringBoot自动配置机制SpringBoot版本:1.5.13.RELEASE 对应官方文档链接:https://docs.spring.io/spring ...

随机推荐

  1. MIMO下的MES均方误差详细推导过程

  2. Linux netstat命令详解

    Linux netstat命令详解 一  简介 Netstat 命令用于显示各种网络相关信息,如网络连接,路由表,接口状态 (Interface Statistics),masquerade 连接,多 ...

  3. eclipse/myeclipse sublime 实时更新文件改变

    情形: 在使用eclipse/myeclipse开发的时候, 像JS 或者HTML 以及一些操作时,sublime 的效率比eclipse/myeclipse要快,所以我们就可以使用这两者一起开发. ...

  4. 关于纯移动web优点的一点思考

    自己造个小概念,纯移动web就是手机浏览器上访问的网站^_^ 缺点就不说了,说几个随着硬件和网络发展会放大的优势. 1 相对app来说,完全无缝对接,只要符合html标准,一次开发全平台部署 2 推广 ...

  5. UVALive 4329 Ping pong(树状数组)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=13895 题意:一条街上住有n个乒乓选手,每个人都有一个技能值,现在 ...

  6. 非对称加密RSA的应用及在C#中的实现

    quote: http://www.cnblogs.com/happinessCodes/archive/2010/07/27/1786404.html   一说到数据的加密,常常会涉及到这几个单词: ...

  7. java设计模式--简单工厂模式

     简单工厂设计模式 工厂模式就是专门负责将大量有共同接口的类实例化,而且不必事先知道每次是要实例化哪一个类的模式.它定义一个用于创建对象的接口,由子类决定实例化哪一个类. 核心知识点如下: (1) 大 ...

  8. C语言atof()函数:将字符串转换为double(双精度浮点数)

    头文件:#include <stdlib.h> 函数 atof() 用于将字符串转换为双精度浮点数(double),其原型为:double atof (const char* str); ...

  9. jquery ajax post 中文乱码解决

    jquery ajax post 方式默认传递的是UFT-8字符,即使页面设置了gbk编码也无效.字符传到后台时如果后台设置的gbk或者其他编码,就会出现乱码.解决很容易,将后台页面设置成UTF-8编 ...

  10. IOS 计时器暂停和开始 防止重复点击

    -(IBAction)btnClick{ [self starTimer];//开始计时 //[self stopTimer]; } -(NSTimer*)timer{ if (!_timer) { ...