springboot提供了基于类型安全的配置方式,通过@ConfigurationProperties将properties属性和一个bean及其属性关联,就可以用bean的方式 使用properties的配置。

【properties文件】:

springboot类型安全配置(基于properties)springboot类型安全配置(基于properties)

【绑定properties和bean】:必须要加@Component注解,该类会交给spring自动去实例化创建对象,交给spring托管。才能在项目里使用注入。

springboot类型安全配置(基于properties)springboot类型安全配置(基于properties)

【调用propertiesBean】:

springboot类型安全配置(基于properties)springboot类型安全配置(基于properties)

相关文章:

  • 2022-02-08
  • 2021-07-27
  • 2021-08-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-11
  • 2021-04-24
猜你喜欢
  • 2022-12-23
  • 2022-01-07
  • 2022-12-23
  • 2022-02-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案