• 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 的一致,不然一致导致配置文件的信息读取不到。

  • 相关阅读:
    前端框架-Bootstrap【搭建后台管理系统】
    前端-jQuery
    前端-js基础语法-DOM
    前端-js基础语法
    前端-html标签
    python学习并发编程
    python学习网络编程
    python爬虫学习:第一爬_快眼看书排行榜
    python总结:模块汇总
    python学习_解释器接口模块:sys
  • 原文地址:https://www.cnblogs.com/outxiao/p/10204403.html
Copyright © 2020-2023  润新知