@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. 【uoj#139】[UER #4]被删除的黑白树 贪心

    题目描述 给出一个 $n$ 个节点的树,$1$ 号点为根.现要将其中一些点染成黑色,使得每个叶子节点(不包括根节点)到根节点路径上的黑点数相同.求最多能够染多少个黑点. 题解 贪心 显然有结论:选择的 ...

  2. Check Corners HDU - 2888(二维RMQ)

    就是板题.. 查询子矩阵中最大的元素...然后看看是不是四个角落的  是就是yes  不是就是no  判断一下就好了 #include <iostream> #include <cs ...

  3. 【转】大数据分析(Big Data OLAP)引擎Dremel, Tenzing 以及Impala

    引自:http://blog.csdn.net/xhanfriend/article/details/8434896 对于数据分析师来说,SQL是主要的语言. Hive为Hadoop提供了支持SQL运 ...

  4. NOIP2015运输计划题解报告

    这题在洛谷上可以找到提交 P2680运输计划 题目背景 公元 2044 年,人类进入了宇宙纪元. 题目描述 L 国有 n 个星球,还有 n-1 条双向航道,每条航道建立在两个星球之间,这 n-1 条航 ...

  5. Jenkins远程代码执行漏洞检查(CVE-2017-1000353)

    Jenkins的反序列化漏洞,攻击者使用该漏洞可以在被攻击服务器执行任意代码,漏洞利用不需要任何的权限 漏洞影响范围: 所有Jenkins主版本均受到影响(包括<=2.56版本)所有Jenkin ...

  6. 《剑指offer》— JavaScript(14)链表中倒数第k个结点

    链表中倒数第k个结点 题目描述 输入一个链表,输出该链表中倒数第k个结点. 思路 两个指针,先让第一个指针和第二个指针都指向头结点,然后再让第一个指正走(k-1)步,到达第k个节点: 然后两个指针同时 ...

  7. poj3613Cow Relays

    Cow Relays Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7683   Accepted: 3017 Descri ...

  8. jetBrains 插件开发第一课-- 在主菜单栏新增一个菜单

    环境搭建完了,接下来可以开始写代码了: 1.新建 plugin 项目 2.编辑 plugin.xml,修改一下里面的插件名那些信息,该文件的配置项可以看这里:plugin.xml 其中比较关键的有一个 ...

  9. Libevent学习笔记(四) bufferevent 的 concepts and basics

    Bufferevents and evbuffers Every bufferevent has an input buffer and an output buffer. These are of ...

  10. C/C++ Volatile关键词深度剖析

    文章来源:http://hedengcheng.com/?p=725 背景 此微博,引发了朋友们的大量讨论:赞同者有之:批评者有之:当然,更多的朋友,是希望我能更详细的解读C/C++ Volatile ...