利用@ConfigurationProperties(prefix = "")来绑定属性时报错:
not registered via @EnableConfigurationProperties or marked as Spring component
 
POM依赖
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-configuration-processor</artifactId>
        <optional>true</optional>
    </dependency>
 
注解需要
    @EnableAutoConfiguration
    @RestController
    @EnableConfigurationProperties({BookController.class})
    @ConfigurationProperties(prefix = "book")
    
    
    正是缺少@EnableConfigurationProperties({BookController.class}),才报该错的
    
    
代码
 
=========================BookController.class====================
 package controller;

 import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@EnableAutoConfiguration
@RestController
@RequestMapping
@ConfigurationProperties(prefix = "book")
public class BookController {
// @Value("${book.author}")
private String author;
//
// @Value("${book.name}")
private String name; @RequestMapping("/bookInfo")
public String showInfo(){
return author + ":" + name;
} }
==================================application.yml===============
 book:
author: Tom
name: Springboot
=========================DemoConfig.class====================
 package controller;

 import org.springframework.boot.SpringApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties; @EnableConfigurationProperties({BookController.class})
public class DemoConfig {
public static void main(String[] args) { SpringApplication.run(BookController.class,args);
}
}
 

not registered via @EnableConfigurationProperties or marked as Spring component的更多相关文章

  1. Spring @ Component 的作用

    1.@controller 控制器(注入服务) 2.@service 服务(注入dao) 3.@repository dao(实现dao访问) 4.@component (把普通pojo实例化到spr ...

  2. spring @Component

    使用 @Component <context:component-scan base-package="dao" />   虽 然我们可以通过@Autowired或@R ...

  3. Spring @Component的作用详细介绍

    @component 作用 1.@controller 控制器(注入服务)2.@service 服务(注入dao)3.@repository dao(实现dao访问)4.@component (把普通 ...

  4. spring @component的作用

    该文转载自:http://tomfish88.iteye.com/blog/1497557 1.@controller 控制器(注入服务) 2.@service 服务(注入dao) 3.@reposi ...

  5. 转!!spring @component 详解 默认初始化bean的名字 VNumberTask类 就是 VNumberTask

    参考链接:信息来源 今天碰到一个问题,写了一个@Service的bean,类名大致为:CUser xml配置: <context:component-scan base-package=&quo ...

  6. Spring @Component 注解的使用

    使用说明 这个注解用于声明当前的类是一个组件类,Spring 会通过类路径扫描来自动侦测和自动装配这些组件,创建一个个 bean 后,注册到 Spring 容器中. 带 @Component 注解的类 ...

  7. Spring Component注解处理过程

    接下来: org.springframework.context.annotation.ComponentScanBeanDefinitionParser#parse方法展开加载过程:

  8. Spring @Component生成bean名称的规则(当类的名字是以两个或以上的大写字母开头的话,bean的名字会与类名保持一致

    正确注入方式: @Autowired private TFeeMapper TFeeMapper; 错误注入方式 @Autowired private TFeeMapper tFeeMapper; 这 ...

  9. SpringBoot @ConfigurationProperties报错

    idea报错如下: Not registered via @EnableConfigurationProperties or marked as Spring component less... (C ...

随机推荐

  1. node+webpack+vue的环境搭建

      一般第一次搭建环境的时候,多多少少还是会出点状况的.这个时候多去百度,看牛人怎么解决,然后跟着尝试,多试几遍还是能解决的. 先说一下我安装的过程吧 1.我一开始按照官网的来搭建,失败了.报错内容是 ...

  2. 新项目UX设计0到1的正确开启方式

    无论是在BAT还是创业小公司,都随时可能接到从0开始的新项目,那么作为负责新项目的主设OR独立设计师,我们应该从何开启工作呢?

  3. 使用cpanel后台的“时钟守护作业”功能完成空间的定时全备份

    现在不少虚拟主机都是使用的cpanel控制面板,由于空间商选用的cpanel版本不同,有的带有定时备份功能,而有的就没有这项功能,需要手动备份.不过,还在绝大部分的cpanel后台都有“时钟守护作业” ...

  4. 关于while循环中的break和continue的区别

    while循环如果不加条件限制的话,它会一直循环下去,那么问题就来了,如果我不用条件去终止while循环的话,那么我该用什么方法去终止呢? 你可以选择两种终止while循环的方法 1.break  强 ...

  5. 【颓废篇】Py:从零开始的poj自动提交

    之前学习了一些python的爬虫技术... 已经可以通过python来水blog的阅读量了 你知道的太多了, 然而你看我这个blog惨不忍睹的访问量, 有人吗? 有人吗? 今天突然又双叒叕心血来潮想写 ...

  6. wireshark 分析 TCP 请求(转)

    转自:http://supben.iteye.com/blog/2329780 先看一段代码  程序片段是一个RPC调用 ,根据简历id获取简历实体.本地IP 10.252.156.132, 远程ip ...

  7. flink idea 打包jar 并放到集群上运行

    flink idea 打包jar 并放到集群上运行 在开始之前注意前提,当前项目的scala的版本要和集群上的scala一致   我已经创建好一个wordCount的flink项目   注意项目的po ...

  8. kubeadm部署一个Kubernetes集群

    kubeadm是官方社区推出的一个用于快速部署kubernetes集群的工具.这个工具能通过两条指令完成一个kubernetes集群的部署: # 创建一个 Master 节点 $ kubeadm in ...

  9. leetcood学习笔记-206-反转链表

    题目描述: 最佳解: class Solution(object): def reverseList(self, head): """ :type head: ListN ...

  10. 分页工具一Pageable与Page

    import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Page; 1.Page ...