Appendix C. XML Schema-based configuration

Appendix C. XML Schema-based configuration

C.2.2 The util schema

First up is coverage of the util tags. As the name
implies, the util tags deal with common, utility
configuration issues, such as configuring collections, referencing constants,
and suchlike.

To use the tags in the util schema, you need to have
the following preamble at the top of your Spring XML configuration file;
the bold text in the snippet below references the correct schema so that
the tags in the util namespace are available to you.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:util="http://www.springframework.org/schema/util"
       xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">

<!-- <bean/> definitions here -->

</beans>
posted on 2012-05-02 18:32  lexus 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/lexus/archive/2012/05/02/2479437.html

Spring Boot Configuration Processor 是一个用于生成配置元数据的注解处理器,可以帮助我们在编译时生成配置元数据,方便 IDE 自动生成配置属性的提示和文档,提高开发效率。 下面是使用 Spring Boot Configuration Processor 的步骤: 1. 添加 Maven 依赖: ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> <optional>true</optional> </dependency> ``` 2. 在配置类上添加 `@ConfigurationProperties` 注解,指定配置属性的前缀: ```java @ConfigurationProperties(prefix = "myconfig") public class MyConfig { private String name; private int age; // getters and setters } ``` 3. 在配置属性上添加 `@ConfigurationProperties` 注解,指定属性名和默认值: ```java public class MyConfig { @ConfigurationProperties("name") private String name = "default"; @ConfigurationProperties("age") private int age = 18; // getters and setters } ``` 4. 在配置类同级目录下创建 `META-INF/spring-configuration-metadata.json` 文件,配置属性的元数据信息: ```json { "groups": [ { "name": "myconfig", "type": "com.example.demo.MyConfig", "sourceType": "com.example.demo.MyConfig" } ], "properties": [ { "name": "myconfig.name", "type": "java.lang.String", "description": "Name of the user", "defaultValue": "default" }, { "name": "myconfig.age", "type": "java.lang.Integer", "description": "Age of the user", "defaultValue": 18 } ] } ``` 5. 在 IDE 中使用配置属性时,会自动提示和补全属性名、类型、描述和默认值等信息。 注意:在使用 `@ConfigurationProperties` 注解时,需要在配置类上添加 `@EnableConfigurationProperties` 注解,或者在 Spring Boot 应用程序主类上添加 `@EnableConfigurationProperties(MyConfig.class)` 注解,才能使属性生效。 参考文档:https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-configuration-metadata.html#configuration-metadata-annotation-processor
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值