利用@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. 解决 IE6 position:fixed 固定定位问题

    #e_float{ _position:absolute; _bottom:auto; _right:50%; _margin-right:-536px; _top:expression(eval(d ...

  2. 36-Ubuntu-用户管理-01-新建用户useradd

    创建用户/设置密码/删除用户/确认用户信息 序号 命令 作用 说明 01 sudo useradd -m -g 组名 新建用户名 添加新用户 -m 自动建立用户家目录 -g 指定用户所在的组,否则会建 ...

  3. Windows进程调度相关

    结构体所在环境: Windows XP Version 2600 (Service Pack 3) UP Free x86 compatible EPROCESS: ntdll!_EPROCESS + ...

  4. C#跨线程访问(一) ---- SynchronizationContext

    一.SynchronizationContext顾名思义是同步上下文的意思.利用此对象可以实现线程间数据的同步.异步访问. 二.例子 class Program { static Thread _wo ...

  5. 淘宝内核月报2014-11-draft

    内核月报2014-11-draft MySQL· 捉虫动态·OPTIMIZE 不存在的表 bug 描述 这是一个和 GTID 相关的Bug,也就是说5.6才会有,并且出现这个 bug 需要满足条件: ...

  6. useradd -帐号建立或更新新使用者的资讯

    总览 SYNOPSIS useradd [-c comment] [-d home_dir] [-e expire_date] [-f inactive_time] [-g initial_group ...

  7. 解决mac下,javac命令出现的乱码问题

    今天突然检查我的jdk安装,发现出现了乱码 一,出现乱码

  8. 生成对抗网络(GAN)的18个绝妙应用

    https://juejin.im/post/5d3fb44e6fb9a06b2e3ccd4e 生成对抗网络(GAN)是生成模型的一种神经网络架构. 生成模型指在现存样本的基础上,使用模型来生成新案例 ...

  9. vue computed和methods 计算属性和侦听器

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  10. MLE极大似然估计和EM最大期望算法

    机器学习十大算法之一:EM算法.能评得上十大之一,让人听起来觉得挺NB的.什么是NB啊,我们一般说某个人很NB,是因为他能解决一些别人解决不了的问题.神为什么是神,因为神能做很多人做不了的事.那么EM ...