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

谢岗网站建设佛山外贸网站建设方案

谢岗网站建设,佛山外贸网站建设方案,国内优秀网站推荐,海口创建公司EnableConfigurationProperties ConfigurationProperties的使用时机 今天在写properties时想到了这个问题#xff0c;为什么有时候我需要写EnableConfigurationProperties有时候又不需要呢#xff1f;下面就详细讲讲。 Data Component ConfigurationProperties(pr…EnableConfigurationProperties ConfigurationProperties的使用时机 今天在写properties时想到了这个问题为什么有时候我需要写EnableConfigurationProperties有时候又不需要呢下面就详细讲讲。 Data Component ConfigurationProperties(prefix hm.auth) public class AuthProperties {private ListString includePaths;private ListString excludePaths; }Component RequiredArgsConstructor public class AuthGlobalFilter implements GlobalFilter, Ordered {private final AuthProperties authProperties;private final JwtTool jwtTool;private final AntPathMatcher antPathMatcher new AntPathMatcher();可以看到AuthGlobalFilter并没有添加EnableConfigurationProperties只是简单的注入就可以使用。 Data ConfigurationProperties(prefix hm.jwt) public class JwtProperties {private Resource location;private String password;private String alias;private Duration tokenTTL Duration.ofMinutes(10); }Configuration EnableConfigurationProperties(JwtProperties.class) public class SecurityConfig {Beanpublic PasswordEncoder passwordEncoder(){return new BCryptPasswordEncoder();}Beanpublic KeyPair keyPair(JwtProperties properties){// 获取秘钥工厂KeyStoreKeyFactory keyStoreKeyFactory new KeyStoreKeyFactory(properties.getLocation(),properties.getPassword().toCharArray());//读取钥匙对return keyStoreKeyFactory.getKeyPair(properties.getAlias(),properties.getPassword().toCharArray());} }可以看到JwtProperties没有添加Component注解也就是没有注册为 Spring 容器中的 bean。然后SecurityConfig中就添加了EnableConfigurationProperties(JwtProperties.class)然后在下面方法中通过参数自动注入public KeyPair keyPair(JwtProperties properties)。 为什么需要 EnableConfigurationProperties 默认情况下使用 ConfigurationProperties 标注的类不会被自动注册为 Spring 容器中的 bean。使用 EnableConfigurationProperties(SecurityConfigProperties.class) 会将该类注册为一个 Spring 管理的 bean使它能够被自动注入。 因为前面JwtProperties没有添加Component注解所以需要添加 EnableConfigurationProperties。而AuthProperties有Component注解也就是已经被spring管理了所以不需要额外添加。 简化方式 如果 SecurityConfigProperties 类本身已经用 Component 标注则无需额外使用 EnableConfigurationProperties。 示例 Component ConfigurationProperties(prefix security) public class SecurityConfigProperties {// 属性和 Getter/Setter 同前 }在这种情况下EnableConfigurationProperties 就变得非必需。 但是如果为了更加稳妥可以把这两个注解全部都加上。Configuration和Component 都可以使其被spring容器管理。 Slf4j Data ConfigurationProperties(prefix zzyl.framework.security) Configuration public class SecurityConfigProperties { }Configuration EnableConfigurationProperties(SecurityConfigProperties.class) public class SecurityConfig {AutowiredSecurityConfigProperties securityConfigProperties;AutowiredJwtAuthorizationManager jwtAuthorizationManager;
http://www.w-s-a.com/news/106324/

相关文章:

  • 怎么将公司网站设成首页网址关键词查询网站
  • 怎么用ps做网站ui邱县专业做网站
  • 国开行网站毕业申请怎么做大连旅顺口旅游攻略
  • 鲜花店网站源码成都专做婚介网站的公司
  • 合肥企业网站建设工哈尔滨公告
  • 华强北 做网站互联网服务平台入口
  • vi设计案例网站微信导航网站 dedecms
  • 青浦区做网站设计图片手绘图片
  • 做网站的基本功制作网站公司推荐
  • 阿里云快速建站教程个人网站 费用
  • 广东购物网站建设微信公众号制作模板免费
  • 阿里国际站韩语网站怎么做让移动网站
  • 北京外包做网站如何报价中国几大网络推广公司
  • 中国建设部网站关于资质wordpress 建app
  • 程序员找工作的网站哈尔滨建设信息网站
  • 公司 网站 方案高考写作网站
  • 网站后台如何登陆网站开发需求逻辑图
  • 市级档案网站建设情况分析server2008做DNS与网站
  • 公积金门户网站建设方案网站建设代理平台怎么做
  • 网站建设知识论文抖音开放平台是干什么的
  • 网站建设期末试卷大气简洁网站
  • 电子商务网站建设报告范文单位做网站怎么做
  • 优质的外国网站qq小程序在哪里打开
  • 商务网站建设与推广实训报告免费素材网站无水印
  • 外贸站seoapp开发公司历程概述
  • 沈阳网站推广¥做下拉去118cr陶瓷企业 瓷砖地板公司网站建设
  • 医院网站官方微信精神文明建设我做服装设计师的 求推荐资源网站
  • 微信网站建设需要那些资料昆明cms模板建站
  • 安庆网站建设兼职中企动力是500强吗
  • 网站排名优化技巧基于网站的网络营销方法有哪些