spring-boot autoConfiguration
一, 第一个待注入类
public class CacheService {
}
public class LoggerService {
}
方法一, 实现接口ImportSelectort
public class CacheImportSelector implements ImportSelector {
@Override
public String[] selectImports(AnnotationMetadata annotationMetadata) {
return new String[]{CacheService.class.getName()};
}
}
方法二, 实现接口ImportBeanDefinitionRegistrar,
public class LoggerServiceSelector implements ImportBeanDefinitionRegistrar {
@Override
public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry beanDefinitionRegistry) {
RootBeanDefinition rootBeanDefinition = new RootBeanDefinition(LoggerService.class);
String strBeanname = StringUtils.uncapitalize(LoggerService.class.getName());
beanDefinitionRegistry.registerBeanDefinition(strBeanname, rootBeanDefinition);
}
}
自定义Enable注解, 将CacheService, LoggerService加载到Spring-boot项目中
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component
@Import({CacheImportSelector.class, LoggerServiceSelector.class})
public @interface EnableCacheService {
}
//启动Spring-boot
@EnableCacheService
@SpringBootApplication
public class SpringBootDemoApplication {
public static void main(String[] args) {
ConfigurableApplicationContext context = SpringApplication.run(SpringBootDemoApplication.class, args);
CacheService cacheService = context.getBean(CacheService.class);
System.out.println(cacheService.toString());
LoggerService loggerService = context.getBean(LoggerService.class);
System.out.println(loggerService);
}
}
spring-boot autoConfiguration的更多相关文章
- How Spring Boot Autoconfiguration Magic Works--转
原文地址:https://dzone.com/articles/how-springboot-autoconfiguration-magic-works In my previous post &qu ...
- 了解 Spring Boot AutoConfiguration
原文:http://sivalabs.in/2016/03/how-springboot-autoconfiguration-magic/ 作者:Siva 译者:http://oopsguy.com ...
- Spring Boot AutoConfiguration注解@ConditionalXXXX之前生今世
1.注解@Conditional的定义 @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE, ElementType.METHO ...
- Spring boot 官网学习笔记 - Auto-configuration(@SpringBootApplication、@EnableAutoConfiguration、@Configuration)
Spring Boot auto-configuration attempts to automatically configure your Spring application based on ...
- Spring Boot文档阅读
原因之初 最初习惯百度各种博客教程,然后跟着操作,因为觉得跟着别人走过的路走可以少走很多弯路,省时间.然而,很多博客的内容并不够完整,甚至错误,看多了的博客甚至有千篇一律的感觉.此外,博客毕竟是记载博 ...
- Spring boot 内存优化
转自:https://dzone.com/articles/spring-boot-memory-performance It has sometimes been suggested that Sp ...
- Spring Boot Memory Performance
The Performance Zone is brought to you in partnership with New Relic. Quickly learn how to use Docke ...
- Spring Boot面试题
Spring Boot 是微服务中最好的 Java 框架. 我们建议你能够成为一名 Spring Boot 的专家. 问题一 Spring Boot.Spring MVC 和 Spring 有什么区别 ...
- spring boot常见问题
1.什么是springboot 用来简化spring应用的初始搭建以及开发过程 使用特定的方式来进行配置(properties或yml文件) 创建独立的spring引用程序 main方法运行 嵌入的T ...
- spring boot多数据源配置(mysql,redis,mongodb)实战
使用Spring Boot Starter提升效率 虽然不同的starter实现起来各有差异,但是他们基本上都会使用到两个相同的内容:ConfigurationProperties和AutoConfi ...
随机推荐
- Linux基本命令及编程环境实验
目录 一.Linux基本命令详细汇总 1.目录及文件相关命令 2.系统信息查询 3.文件操作(统计.过滤.搜索.权限) 4.其他命令 二.Linux终端上vi命令编程 1.进入vi命令模式 2.vi编 ...
- PHP to .NET Compiler
官网 https://github.com/peachpiecompiler/peachpie 非官方简介 https://blog.csdn.net/sD7O95O/article/details/ ...
- LightOJ - 1214-Large Division(c++取模 + java的两种写法)
Given two integers, a and b, you should check whether a is divisible by b or not. We know that an in ...
- 下拉列表被flash覆盖的解决方法
做鼎闻有一段时间了,有的banner轮播图的地方用flash替换的时候,就会导致上面的导航条下拉列表被flash覆盖,找了一段时间没有得到有效的解决方法,后来知道关键是flash的这一属性{ &quo ...
- GET请求和POST请求的request和response的中文乱码问题
GET请求(request)中文乱码解决方案: 在Services的server.xml的配置文件的第一个Connector标签中添加属性URIEncoding="UTF-8" P ...
- 原生JDK网络编程BIO
服务端提供IP和监听端口,客户端通过连接操作想服务端监听的地址发起连接请求,通过三次握手连接,如果连接成功建立,双方就可以通过套接字进行通信. 传统的同步阻塞模型开发中,ServerSocket负责绑 ...
- leetcode刷题-79单词搜索
题目 给定一个二维网格和一个单词,找出该单词是否存在于网格中. 单词必须按照字母顺序,通过相邻的单元格内的字母构成,其中“相邻”单元格是那些水平相邻或垂直相邻的单元格.同一个单元格内的字母不允许被重复 ...
- node.js之koa安装
默认安装了node 1.cmd中工作目录下输入npm init:一路回车即可: 2.还是在此目录下输入npm i koa:我这里是安装的淘宝镜像即是输入cpm i koa. 3.打开编辑器在文件目录下 ...
- python3中抛异常except后面参数
try: xxx except exception as e: print("给exception取了个别名叫做e") else: ccc
- 吴恩达《深度学习》-第五门课 序列模型(Sequence Models)-第一周 循环序列模型(Recurrent Neural Networks) -课程笔记
第一周 循环序列模型(Recurrent Neural Networks) 1.1 为什么选择序列模型?(Why Sequence Models?) 1.2 数学符号(Notation) 这个输入数据 ...