一, 第一个待注入类

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

  1. How Spring Boot Autoconfiguration Magic Works--转

    原文地址:https://dzone.com/articles/how-springboot-autoconfiguration-magic-works In my previous post &qu ...

  2. 了解 Spring Boot AutoConfiguration

    原文:http://sivalabs.in/2016/03/how-springboot-autoconfiguration-magic/ 作者:Siva 译者:http://oopsguy.com ...

  3. Spring Boot AutoConfiguration注解@ConditionalXXXX之前生今世

    1.注解@Conditional的定义 @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE, ElementType.METHO ...

  4. Spring boot 官网学习笔记 - Auto-configuration(@SpringBootApplication、@EnableAutoConfiguration、@Configuration)

    Spring Boot auto-configuration attempts to automatically configure your Spring application based on ...

  5. Spring Boot文档阅读

    原因之初 最初习惯百度各种博客教程,然后跟着操作,因为觉得跟着别人走过的路走可以少走很多弯路,省时间.然而,很多博客的内容并不够完整,甚至错误,看多了的博客甚至有千篇一律的感觉.此外,博客毕竟是记载博 ...

  6. Spring boot 内存优化

    转自:https://dzone.com/articles/spring-boot-memory-performance It has sometimes been suggested that Sp ...

  7. Spring Boot Memory Performance

    The Performance Zone is brought to you in partnership with New Relic. Quickly learn how to use Docke ...

  8. Spring Boot面试题

    Spring Boot 是微服务中最好的 Java 框架. 我们建议你能够成为一名 Spring Boot 的专家. 问题一 Spring Boot.Spring MVC 和 Spring 有什么区别 ...

  9. spring boot常见问题

    1.什么是springboot 用来简化spring应用的初始搭建以及开发过程 使用特定的方式来进行配置(properties或yml文件) 创建独立的spring引用程序 main方法运行 嵌入的T ...

  10. spring boot多数据源配置(mysql,redis,mongodb)实战

    使用Spring Boot Starter提升效率 虽然不同的starter实现起来各有差异,但是他们基本上都会使用到两个相同的内容:ConfigurationProperties和AutoConfi ...

随机推荐

  1. muduo源码解析7-countdownlatch类

    countdownlatch class countdownlatch:noncopyable { }; 作用: countdownlatch和mutex,condition一样,用于线程之间的同步, ...

  2. 【独家】React Native 版本升级指南

    前言 React Native 作为一款跨端框架,有一个最让人头疼的问题,那就是版本更新.尤其是遇到大版本更新,JavaScript.iOS 和 Android 三端的配置构建文件都有非常大的变动,有 ...

  3. 【转】Echarts自适应

    var myChart1 = echarts.init(document.getElementById('chart1')); var option = myChart1.getOption(); w ...

  4. 使用tensorflow2识别4位验证码及思考总结

    在学习了CNN之后,自己想去做一个验证码识别,网上找了很多资料,杂七杂八的一大堆,但是好多是tf1写的,对tf1不太熟悉,有点看不懂,于是自己去摸索吧. 摸索的过程是异常艰难呀,一开始我直接用capt ...

  5. 分分钟玩转UI自动化测试

    有没有那么一刻,看到自动模拟用户操作界面感觉好神奇. 关于什么叫 UI 自动化测试就不解释了,基本上是你刚才脑海里想到什么就是什么. 在分层自动化测试中包括:UI 测试.集成/接口测试.单元测试.大神 ...

  6. Salesforce LWC学习(二十二) 简单知识总结篇二

    本篇参看: https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.reactivity_fi ...

  7. vmware虚拟机Bridged(桥接模式)、NAT(网络地址转换模式)、Host-Only(仅主机模式)详解

    原文来自http://note.youdao.com/share/web/file.html?id=236896997b6ffbaa8e0d92eacd13abbf&type=note 我怕链 ...

  8. IO优化

    Linux性能优化之CPU.内存.IO优化 https://blog.csdn.net/zyc88888/article/details/79027944 iOS的I/O操作 https://www. ...

  9. HashMap源码解析、jdk7和8之后的区别、相关问题分析(多线程扩容带来的死循环)

    一.概览 HashMap<String, Integer> map = new HashMap<>(); 这个语句执行起来,在 jdk1.8 之前,会创建一个长度是 16 的 ...

  10. 用安卓 WebView 做一个“套壳”应用

    前言 目前手机应用市场上的 APP 类型主要为以下两种: Native App(原生应用):直接针对平台(Android.iOS 等手机系统)进行开发,属于性能最优的方案,也是开发成本最大的方案. H ...