首页 > 其他分享 >自定义配置文件参数在application可以直接识别Not registered via @EnableConfigurationProperties or marked as Spring com

自定义配置文件参数在application可以直接识别Not registered via @EnableConfigurationProperties or marked as Spring com

时间:2023-09-08 11:57:11浏览次数:45  
标签:String 配置文件 Spring age 自定义 password public name

自定义配置文件参数在application可以直接识别Not registered via @EnableConfigurationProperties or marked as Spring component

看见很多开源项目的配置文件可以直接配置在application.yaml中,自己也想弄一个,怎么弄呢?

这是我的demo,你正常ConfigurationProperties会报错Not registered via @EnableConfigurationProperties or marked as Spring component

@Component
@ConfigurationProperties("zuul2")
public class Zuul2Properties {

    private String name;
    private Integer  age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    private  String password;

}

需要加一个这个。

	<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-configuration-processor</artifactId>
			<optional>true</optional>
		</dependency>

需要maven手动编译一下就能展示出来了、compile.实测好使

image-20230908114248410

标签:String,配置文件,Spring,age,自定义,password,public,name
From: https://www.cnblogs.com/q1359720840/p/17687213.html

相关文章

  • 为什么 springboot 项目中 使用 lombok 不需要指定版本
    springboot默认管理了lombok的版本依赖,所以不需要指定版本号SpringBoot项目中使用Lombok不需要显式指定Lombok的版本,是因为SpringBoot的父项目(spring-boot-starter-parent)已经为您管理了Lombok的版本。这是通过在SpringBoot的父项目中的dependencyManagement部分指定Lombok的......
  • SpringSecurity中注解讲解
    目录[email protected]@PreAuthorize1.1.1开启注解1.1.2使用注解原生方法1.1.3使用注解自定义方法[email protected]@Secured2其他注解[email protected]@PreFilter3权限表达式1@EnableGlobalMethodSecurity@EnableGlobalMethodSecurity是Spring......
  • 构建自定义美颜应用:全局美颜SDK的开发指南
    美颜技术已经成为许多应用程序和平台的标配之一,为用户提供了改善外观的机会。为了在你的应用中提供自定义的美颜功能,你可以考虑使用全局美颜SDK。本文将向你介绍如何构建自定义美颜应用,以及开发全局美颜SDK的关键步骤和技巧。一、明确需求和目标在开始之前,你需要明确你的美颜应用的......
  • springmvc中的json数据转为字符串使用到的jar包,将servlet设置为bean对象
    2023-09-08<dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-databind</artifactId><version>2.15.2</version></dependency>ServletConfigp......
  • 样本分析 99eddc2794077f97a5cfe3098f431c4cfc4fd6353957ee715b2eccbff066ce1d 由于.
     https://s.threatbook.com/report/file/99eddc2794077f97a5cfe3098f431c4cfc4fd6353957ee715b2eccbff066ce1d09:30:16:088, 99eddc2794077f97a5cfe3098f431c4cfc4fd6353957ee715b2eccbff066ce1d.exe, 1908:0, 1908, EXEC_create, C:\Users\bonelee\Desktop\99eddc2794077......
  • springboot实现 伪微信登录
    众所周知,微信扫码登陆的功能,个人网站是无法申请的,我们想在本地测一下微信登录也是无法实现。要实现微信登录,首先你得是一个企业单位,有公章才能申请,申请还要花费300块大洋。如果我们只是想学习和体验一下微信登录,可以自己本地搭建个微型服务模拟一下,过一把瘾也是可以的。如果你是企......
  • 详谈SpringBoot启动项目后执行自定义方法的方式
    在main启动函数中调用这个是在所有启动后执行,也是常用之一。@SpringBootApplicationpublicclassListenerApplication{publicstaticvoidmain(String[]args){SpringApplication.run(ListenerApplication.class,args);System.out.println("启动成......
  • springboot - idea - active: @profileActive@ 有时候 不识别 @ 导致启动失败
    1.背景有时候正常,有时候不行,特别是maven执行了clean命令后 2.解决右键执行一下这个即可 ......
  • Spring整合Mybatis
    Spring整合Mybatis就是将原本Mybatis中的Mapper.xml文件在Spring容器中注册为对象。导入mybatis-spring依赖包<dependency><groupId>org.mybatis</groupId><artifactId>mybatis-spring</artifactId><version>1.3.2</version></dependency>......
  • pageoffice 6版本隐藏office工具栏和自定义按钮,并修改标题栏内容
    在实际项目集成调用PageOffice的过程中:(1)有时需要把Office的工具栏隐藏,比如只读模式打开文件的时候,Office工具栏上的按钮几乎都是灰掉的,此时显示Office工具栏没有任何意义,并且浪费了宝贵的界面空间。实现此功能只需在OnPageOfficeCtrlInit事件中调用js设置PageOffice控件的Office......