利用@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. CSS 案例学习

    1.样式 display:inline-block;可改变a标签,合其可定义宽高 2.a:hover表示鼠标经过 3.background:url(110.png) bottom 表示:给链接一个图片 ...

  2. Cause: java.sql.SQLDataException: ORA-01861: 文字与格式字符串不匹配

  3. Django项目从新建到运行

    返回主目录:Django框架 内容目录: 一.安装之前 二.Django安装 三.创建项目 四.配置 一.安装之前 安装django之前你需要注意的几个事项: 1.版本问题 建议使用1.11.11左右 ...

  4. Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci...

    最近刚接触mysql,今天用mysql插入中文字符的时候,程序报错“Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_g ...

  5. html input 上capture 参数在 安卓 苹果上的异同

    安卓上 <input type="file" accept="image/*" capture="camera"> //只调用相 ...

  6. python代码{v: k for k, v in myArray.items()}是什么意思?

    最近在扒vnpy的源码总能看到{v: k for k, v in ORDERTYPE_VT2HUOBI.items()}这样的源码,就是不知道什么意思 然后万能的google找到了Quora的一个类似 ...

  7. 针对list<object>中的对象数据的一些简单处理

    一    首先创建一个实体类(PersonData ): package hello; public class PersonData { String Id; String Name; String ...

  8. thinkphp 模块部署

    3.2对模块的访问是自动判断的,所以通常情况下无需配置模块列表即可访问,在部署模块的时候,默认情况下都是基于类似于子目录的URL方式来访问模块的,例如: http://serverName/Home/ ...

  9. Android下载Android源码

    使用Git,命令是:git clone http://android.googlesource.com/platform/frameworks/base.git

  10. 线性dp——cf988F

    不是很难,dp[i]表示到位置i的最小花费 #include<bits/stdc++.h> using namespace std; #define ll long long #defin ...