当前位置: 首页 > news >正文

网站架构设计师wordpress分类列表去掉分类目录

网站架构设计师,wordpress分类列表去掉分类目录,医疗网站平台建设方案,白云手机网站建设价格EnableConfigurationProperties注解的用法 EnableConfigurationProperties 是 Spring Boot 中的一个注解#xff0c;用于启用对 ConfigurationProperties 注解的支持。它通常用于将配置属性绑定到一个 Java Bean 上。以下是它的用法和示例#xff1a; 1. 创建配置属性类 首…EnableConfigurationProperties注解的用法 EnableConfigurationProperties 是 Spring Boot 中的一个注解用于启用对 ConfigurationProperties 注解的支持。它通常用于将配置属性绑定到一个 Java Bean 上。以下是它的用法和示例 1. 创建配置属性类 首先创建一个 Java 类用于存储配置属性。这个类需要使用 ConfigurationProperties 注解并且通常还需要 Component 注解或者在 Spring Boot 2.2 及以上版本中可以省略 Component 注解直接使用 EnableConfigurationProperties 注解来注册这个类。 import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component;Component ConfigurationProperties(prefix app) public class AppProperties {private String name;private String version;// getters and setterspublic String getName() {return name;}public void setName(String name) {this.name name;}public String getVersion() {return version;}public void setVersion(String version) {this.version version;} }2. 启用配置属性 在你的配置类通常是主应用程序类中使用 EnableConfigurationProperties 注解来启用配置属性支持。 import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.properties.EnableConfigurationProperties;SpringBootApplication EnableConfigurationProperties(AppProperties.class) public class MyApplication {public static void main(String[] args) {SpringApplication.run(MyApplication.class, args);} }3. 在配置文件中定义属性 在 application.properties 或 application.yml 文件中定义属性 # application.properties app.nameMyApp app.version1.0.0或者 # application.yml app:name: MyAppversion: 1.0.04. 使用配置属性 你可以在任何需要的地方注入并使用这些配置属性 import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController;RestController public class MyController {private final AppProperties appProperties;Autowiredpublic MyController(AppProperties appProperties) {this.appProperties appProperties;}GetMapping(/info)public String getAppInfo() {return App Name: appProperties.getName() , Version: appProperties.getVersion();} }总结 ConfigurationProperties 注解用于将配置文件中的属性映射到 Java 类。EnableConfigurationProperties 注解用于启用对 ConfigurationProperties 注解的支持。配置属性类可以通过 Component 注解注册为 Spring Bean或者通过 EnableConfigurationProperties 注解进行注册。在配置文件中定义属性并在需要的地方注入和使用这些属性。 在 EnableConfigurationProperties 注解中如果不指定具体的配置属性类例如 AppProperties.class那么这个注解将不会启用任何特定的配置属性类。这意味着 Spring Boot 将不会自动扫描和注册任何使用 ConfigurationProperties 注解的类。 具体影响 配置属性类不会被注册如果你没有在 EnableConfigurationProperties 中指定具体的类那么即使你定义了带有 ConfigurationProperties 注解的类这些类也不会被 Spring 容器管理和注册为 Bean。 无法自动绑定配置属性由于配置属性类没有被注册Spring Boot 将无法将配置文件中的属性自动绑定到这些类上。 示例 假设你有一个配置属性类 AppProperties import org.springframework.boot.context.properties.ConfigurationProperties;ConfigurationProperties(prefix app) public class AppProperties {private String name;private String version;// getters and setters }如果你在主应用程序类中使用 EnableConfigurationProperties 注解但没有指定 AppProperties.class import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.properties.EnableConfigurationProperties;SpringBootApplication EnableConfigurationProperties public class MyApplication {public static void main(String[] args) {SpringApplication.run(MyApplication.class, args);} }在这种情况下AppProperties 类将不会被注册为 Spring Bean配置文件中的属性也不会被绑定到 AppProperties 类。 解决方法 为了确保配置属性类被正确注册和绑定你需要在 EnableConfigurationProperties 注解中指定具体的类 SpringBootApplication EnableConfigurationProperties(AppProperties.class) public class MyApplication {public static void main(String[] args) {SpringApplication.run(MyApplication.class, args);} }总结 不指定具体类配置属性类不会被注册配置文件中的属性不会被绑定。指定具体类配置属性类会被注册配置文件中的属性会被自动绑定到这些类上。 为了确保配置属性类能够正常工作建议在 EnableConfigurationProperties 注解中指定具体的配置属性类。 如果你不想在 EnableConfigurationProperties 注解中指定具体的配置属性类可以使用 ConfigurationPropertiesScan 注解来自动扫描和注册所有带有 ConfigurationProperties 注解的类。 使用 ConfigurationPropertiesScan ConfigurationPropertiesScan 是 Spring Boot 2.2 引入的一个注解它可以自动扫描指定包及其子包中的所有 ConfigurationProperties 类并将它们注册为 Spring Bean。 示例 你可以在主应用程序类中使用 ConfigurationPropertiesScan 注解而不需要在 EnableConfigurationProperties 中指定具体的类 import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.properties.ConfigurationPropertiesScan;SpringBootApplication ConfigurationPropertiesScan public class MyApplication {public static void main(String[] args) {SpringApplication.run(MyApplication.class, args);} }
http://www.pierceye.com/news/398322/

相关文章:

  • 网站建设产品介绍烟台定制网站建设电话
  • 公司内部网站设计客户关系管理策略
  • 个人开发网站要多少钱梅州市城乡建设局网站
  • 外贸公司网站案例建设银行报考网站
  • 网站设计建设步骤做暖网站
  • dw如何做网站界面全网推广外包公司
  • 企业网站数据库建设菠菜网站
  • 网站功能优化的方法营销型网站建设集装箱液袋
  • 建设资讯网站厦门网站建设哪家强
  • 惠阳网站设计开发图片做多的网站是哪个
  • 医院网站建设公司价格低本地网站搭建视频教程
  • 黑客攻击的网站网站开发需要多少钱app
  • 海南建设厅评审网站织梦网站加网站地图
  • 清迈城市建设网站外贸搜索网站
  • 怎样做网站公司网站建设维护管理
  • 伊犁网站制作珠海做网站的公司
  • 乐山市规划和建设局网站房地产基础知识
  • 网站给假冒伪劣产品做推广鞍山网站制作一般需要多少钱
  • 番禺网站开发哪里好ppt模板免费下载完整版免费简约
  • 哪个公司做企业网站好济南网站优化推广公司电话
  • 深圳网站建设外包公司网站流量提供商
  • 网站建设优化服务信息wordpress下载类插件
  • 深圳做网站google推广百度优化是什么
  • 网站开发技术服务费分享经济网站怎么建设
  • 免费seo网站推广在线观看360免费wifi创建失败
  • 服装网站开发嵌入式硬件开发
  • 上海建设厅网站那些网站可以做自媒体
  • 如何查看一个网站流量网店美工课程心得体会
  • 邯郸的网站建设无锡做网站品牌公司
  • 汇编做网站门户网站建设 知乎