@Component

Compent等效于xml文件中的Bean标注,Autowired自动初始化Bean是通过查找Component注解实现的,在增加Component后还是Autowired找不到的情况,应该是在main类中没有增加ComponentScan注解。

@SpringBootApplication
@ComponentScan(basePackages = "com.xx.aa.requester.producter")
public class TestApplication { public static void main(String[] args){ SpringApplication.run(TestApplication.class,args); } }

@ConfigurationProperties 读取配置文件

ConfigurationProperties注解用于标注读取配置文件的节点,PropertySource用于标注文件,如果PropertySource不设置,默认读取application.properties或application.yml文件。

@Component("queueConfiguration")
@ConfigurationProperties(prefix = "requester.rocketmq", )
public class QueueConfiguration { private String rocketHost; public String getRocketHost() {
return rocketHost;
} public void setRocketHost(String rocketHost) {
this.rocketHost = rocketHost;
} public String getTopic() {
return topic;
} public void setTopic(String topic) {
this.topic = topic;
} private String topic; }

调用配置文件

@Component("queueProducter")
public class QueueProducter { @Autowired
QueueConfiguration queueConfiguration; public void SendQueue(){ System.out.println(queueConfiguration.getRocketHost()); } }

测试用例

@RunWith(SpringRunner.class)
@SpringBootTest(classes=TestApplication.class,
webEnvironment = SpringBootTest.WebEnvironment.NONE)
public class QueueProducterTest { @Autowired
QueueProducter queueProducter; @Test
public void testQueue(){ System.out.println(">>>>>>>>>>>>>> testing...");
queueProducter.SendQueue();
}
}

 AutoConfig

AutoConfig是在跨jar引用的时候的一种自动配置实现,增加resource/META-INF/spring.factories文件,配置:

org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.aa.aaConfig,com.aa.aaComponent

Maven中Test Resource支持

在idea中配置模块的Test Resource,在Maven中编译时执行测试单元时失效,可以增加maven的test resource配置build节点中增加:
<build>
<testResources>
<testResource>
<directory>${project.basedir}/src/test/resource</directory>
</testResource>
</testResources>
</build>

spring boot注解学习记的更多相关文章

  1. Spring Boot 项目学习 (二) MySql + MyBatis 注解 + 分页控件 配置

    0 引言 本文主要在Spring Boot 基础项目的基础上,添加 Mysql .MyBatis(注解方式)与 分页控件 的配置,用于协助完成数据库操作. 1 创建数据表 这个过程就暂时省略了. 2 ...

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

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

  3. Spring Boot 项目学习 (四) Spring Boot整合Swagger2自动生成API文档

    0 引言 在做服务端开发的时候,难免会涉及到API 接口文档的编写,可以经历过手写API 文档的过程,就会发现,一个自动生成API文档可以提高多少的效率. 以下列举几个手写API 文档的痛点: 文档需 ...

  4. Spring Boot 项目学习 (三) Spring Boot + Redis 搭建

    0 引言 本文主要介绍 Spring Boot 中 Redis 的配置和基本使用. 1 配置 Redis 1. 修改pom.xml,添加Redis依赖 <!-- Spring Boot Redi ...

  5. Spring Boot 项目学习 (一) 项目搭建

    0 引言 本文主要记录借用Idea 开发环境下,搭建 Spring Boot 项目框架的过程. 1 系列文档目录 Spring Boot 项目学习 (一) 项目搭建 Spring Boot 项目学习 ...

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

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

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

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

  8. Spring boot 注解简单备忘

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

  9. Spring Boot的学习之路(03):基础环境搭建,做好学习前的准备工作

    1. 前言 <论语·魏灵公>:"工欲善其事,必先利其器.居是邦也,事其大夫之贤者,友其士之仁者." 工欲善其事必先利其器.我们在熟悉一个陌生项目的时候,首先会大概去看一 ...

随机推荐

  1. 循环 与 next()

  2. HDFS集中式的缓存管理原理与代码剖析--转载

    原文地址:http://yanbohappy.sinaapp.com/?p=468 Hadoop 2.3.0已经发布了,其中最大的亮点就是集中式的缓存管理(HDFS centralized cache ...

  3. 【bzoj1430】小猴打架 Prufer序列

    题目描述 给出 $n$ 个点,每次选择任意一条边,问这样 $n-1$ 次后得到一棵树的方案数是多少. 输入 一个整数N. 输出 一行,方案数mod 9999991. 样例输入 4 样例输出 96 题解 ...

  4. BZOJ4883 棋盘上的守卫(环套树+最小生成树)

    容易想到网络流之类的东西,虽然范围看起来不太可做,不过这提供了一种想法,即将行列分别看做点.那么我们需要找一种连n+m条边的方案,使得可以从每条边中选一个点以覆盖所有点.显然每个点至少要连一条边.于是 ...

  5. 51nod 1766 树上的最远点对(线段树)

    像树的直径一样,两个集合的最长路也是由两个集合内部的最长路的两个端点组成的,于是我们知道了两个集合的最长路,枚举一下两两端点算出答案就可以合并了,所以就可以用线段树维护一个区间里的最长路了. #inc ...

  6. Codeforces Round #301 (Div. 2)A B C D 水 模拟 bfs 概率dp

    A. Combination Lock time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  7. lightoj 1020 (博弈水题)

    lightoj 1020 A Childhood Game 链接:http://lightoj.com/volume_showproblem.php?problem=1020 题意:一堆石子有 m 个 ...

  8. Nginx--try_files

    Nginx的配置语法灵活,可控制度非常高.在0.7以后的版本中加入了一个try_files指令,配合命名location,可以部分替代原本常用的rewrite配置方式,提高解析效率.   作用域:se ...

  9. mongoDB与sql聚合操作对应图

    SQL Terms, Functions, and Concepts MongoDB Aggregation Operators WHERE $match GROUP BY $group HAVING ...

  10. R1(上)—R关联规则分析之Arules包详解

    Arules包详解 包基本信息 发布日期:2014-12-07 题目:挖掘关联规则和频繁项集 描述:提供了一个表达.处理.分析事务数据和模式(频繁项集合关联规则)的基本框架. URL:http://R ...