利用@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. Matlab转opencv遇到的坑

    之前在学校里面做研究用都是Matlab,后来工作中因为对算法的实时性有很高的要求,所以转向了opencv.我想我遇到的第一大坑就是opencv默认的通道顺序是BGR而不是RGB. 这个顺带的就是灰度化 ...

  2. JUC源码分析-集合篇(六)LinkedBlockingQueue

    JUC源码分析-集合篇(六)LinkedBlockingQueue 1. 数据结构 LinkedBlockingQueue 和 ConcurrentLinkedQueue 一样都是由 head 节点和 ...

  3. js中常用的正则表达式

    我一般对正则的使用方式如下,该方法会返回一个boolean值,然后对这个返回值来进行判断 // 判断是否是整数 function isInt(num) { var reg = new RegExp(& ...

  4. (数据科学学习手札61)xpath进阶用法

    一.简介 xpath作为对网页.对xml文件进行定位的工具,速度快,语法简洁明了,在网络爬虫解析内容的过程中起到很大的作用,除了xpath的基础用法之外(可参考我之前写的(数据科学学习手札50)基于P ...

  5. C# 编译生成 产生多余的语言包删除"de" "en" "es" "fr" "hu" "it" "ja" "ko" "pr-br" "ro" "pt-br" "ru" "sv" "zh-hans" "zh-hant&qu

    VS生成事件 rd /s /q "de" "en" "es" "fr" "hu" "it& ...

  6. sanic连接mongo

    方法一: #没有密码,就是没有用户和用户密码 settings={"MOTOR_URI":"mongodb://127.0.0.1:27017/zzy"} ap ...

  7. 将Java和Javac的命令在控制台的输出重定向到txt文件

    当我们在Windows控制台窗口执行程序时,输入如下命令: demo.exe > out.txt 就可以把demo程序的输出重定向到out.txt文件里面. 但是这种方法对于java和javac ...

  8. Linux 网络 tcp C/S通信模型

    C/S模型就是server 与 client 的模型 TCP服务器模型流程图                                                              ...

  9. 基于nginx+tomcat部署商城系统并连接数据库

    需三台服务器nginx 192.168.200.111tomcat 192.168.200.112tomcat 192.168.200.113 192.168.200.111[root@localho ...

  10. android是32-bit系统还是64-bit系统

    转自:http://www.cnblogs.com/pengwang/archive/2013/03/11/2954496.html 电脑CPU分32位和64位,这个我们都知道.用了这么长时间的and ...