Springboot使用@ConfigurationProperties注解 配置读不进去

首先写依赖

1 <dependency>
2      <groupId>org.springframework.boot</groupId>
3     <artifactId>spring-boot-configuration-processor</artifactId>
4     <optional>true</optional>
5 </dependency>

@ConfigurationProperties注解的类如下

@ConfigurationProperties(prefix = "club.wenfan.security.browser")
public class SecurityProperties {

private VaidateCodeProperties code = new VaidateCodeProperties();
public VaidateCodeProperties getCode() {
        return code;
    }

    public void setCode(VaidateCodeProperties code) {
        this.code = code;
    }

}
VaidateCodeProperties类如下 
package club.wenfan.security.core.properties;

/**
 * @author:wenfan
 * @description:
 * @data: 2019/1/1 9:31
 */
public class VaidateCodeProperties {

    private ImgCodeProperties img=new ImgCodeProperties();

    public ImgCodeProperties getImg() {
        return img;
    }

    public void setImg(ImgCodeProperties img) {
        this.img = img;
    }
}
ImgCodeProperties 类如下
package club.wenfan.security.core.properties;

/**
 * @author:wenfan
 * @description:
 * @data: 2019/1/1 9:21
 */
public class ImgCodeProperties {

    private  int width = 100;// 定义图片的width
    private  int height= 30;// 定义图片的height
    private  int codeCount = 4;// 定义图片上显示验证码的个数
    private int  expiredTime = 60;

    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public int getCodeCount() {
        return codeCount;
    }

    public void setCodeCount(int codeCount) {
        this.codeCount = codeCount;
    }

    public int getExpiredTime() {
        return expiredTime;
    }

    public void setExpiredTime(int expiredTime) {
        this.expiredTime = expiredTime;
    }
}

配置文件如下

club.wenfan.security.browser.code.img.height=100
club.wenfan.security.browser.code.img.width=100
club.wenfan.security.browser.code.img.codeCount=4
club.wenfan.security.browser.code.img.expiredTime=60

经过多次尝试,发现:对象名一定要和 Set、 Get 的一致,不然一致导致配置文件的信息读取不到。

原文地址:https://www.cnblogs.com/outxiao/p/10204403.html

时间: 2024-07-31 12:58:41

Springboot使用@ConfigurationProperties注解 配置读不进去的相关文章

SpringBoot#ConfigurationProperties注解相关的一些知识

用途:ConfigurationProperties注解,用于在spring环境定义bean的时候.通过这个注解,把配置文件中的相关属性注入到实例化的bean中. 原理:spring中bean的生命周期特性.容器处理ConfigurationProperties注解所标注的方法(设为M1),会调用实现了某一个实现了BeanPostProcessor的bean后置处理器,这个处理器会通过ConfigurationProperties指定的prefix从配置文件中读取属性与值,赋给M1所创建的bea

springBoot基础系列--properties配置

原创作品,可以转载,但是请标注出处地址:http://www.cnblogs.com/V1haoge/p/7183408.html SpringBoot中免除了大部分手动配置,但是对于一些特定的情况,还是需要我们进行手动配置的,SpringBoot为我们提供了application.properties配置文件,让我们可以进行自定义配置,来对默认的配置进行修改,以适应具体的生产情况,当然还包括一些第三方的配置.几乎所有配置都可以写到application.peroperties文件中,这个文件会

springboot + shiro 权限注解、请求乱码解决、统一异常处理

springboot + shiro 权限注解.请求乱码解决.统一异常处理 前篇 后台权限管理系统 相关: spring boot + mybatis + layui + shiro后台权限管理系统 springboot + shiro之登录人数限制.登录判断重定向.session时间设置 springboot + shiro 动态更新用户信息 基于前篇,新增功能: 新增shiro权限注解: 请求乱码问题解决: 统一异常处理. 源码已集成到项目中: github源码: https://githu

springboot+ibatis 多数据源配置

这个是boot基本版本包,因为我用的打包方式是war所以去除掉了boot内置的tomcat,但是为了方便测试又引入了内置tomcat,只要添加<scope>provided</scope>在打包时就不会影响了. <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> &l

SpringBoot(15)—@Conditional注解

SpringBoot(15)-@Conditional注解 作用 @Conditional是Spring4新提供的注解,它的作用是按照一定的条件进行判断,满足条件的才给容器注册Bean. 一.概述 1.@Conditional注解定义 @Target({ElementType.TYPE, ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface Conditional { Clas

007 SpringBoot的@EnableAutoConfiguration注解

一:原理 1. 首先Spring Boot项目中都会如下启动类: @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } 其中,@SpringBootApplication中有三个重要的注解合一. @Target(ElementType.TYPE) @Retention

详解SSH注解配置,bean注解、事物注解等

使用过SSH注解的屌丝们都知道,要想使用注解需要在applicationContext.xml配置文件里面开启注解配置,开启方式如下:1.头部声明需加入xmlns:context="http://www.springframework.org/schema/context"http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3

Hibernate初学---注解配置

ssh框架是每个java程序员的基本功,工作中虽然没有用到,还是学习一下,做点学习笔记,算是一点积累吧. 废话不多说,先上手来一个简单的demo,感受一把. 开发工具:myeclipse 10 数据库:mysql 创建个简单的java工程, 第一步,创建一个学生类,代码如下: package com.huawei.vo; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.p

SpringBoot使用Mybatis注解进行一对多和多对多查询(2)

SpringBoot使用Mybatis注解进行一对多和多对多查询 GitHub的完整示例项目地址kingboy-springboot-data 一.模拟的业务查询 系统中的用户user都有唯一对应的地址信息address,每个用户可以有多量车car,类似如下结构 |-- user |-- address |-- carList |-- car1 |-- car2 二.对应的实体类如下 /省略setter/getter public class Address { private Long id;