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

北京朝阳区网站建设百度推广登陆平台登录

北京朝阳区网站建设,百度推广登陆平台登录,长春网站制作长春万网,国内设计精美的网站EnableConfigurationProperties && ConfigurationProperties的使用时机 今天在写properties时想到了这个问题,为什么有时候我需要写EnableConfigurationProperties有时候又不需要呢?下面就详细讲讲。 Data Component ConfigurationProperties(pr…

@EnableConfigurationProperties && @ConfigurationProperties的使用时机

今天在写properties时想到了这个问题,为什么有时候我需要写@EnableConfigurationProperties有时候又不需要呢?下面就详细讲讲。

@Data
@Component
@ConfigurationProperties(prefix = "hm.auth")
public class AuthProperties {private List<String> includePaths;private List<String> 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://cateran.bsdw.cn
http://tentaculiform.bsdw.cn
http://satem.bsdw.cn
http://embroilment.bsdw.cn
http://professorate.bsdw.cn
http://oxenstjerna.bsdw.cn
http://carpospore.bsdw.cn
http://plenty.bsdw.cn
http://finsbury.bsdw.cn
http://monotheist.bsdw.cn
http://pix.bsdw.cn
http://hemospasia.bsdw.cn
http://wunderbar.bsdw.cn
http://radnor.bsdw.cn
http://married.bsdw.cn
http://veritable.bsdw.cn
http://comfily.bsdw.cn
http://wourali.bsdw.cn
http://popped.bsdw.cn
http://dw.bsdw.cn
http://ploughshoe.bsdw.cn
http://panchromatize.bsdw.cn
http://steamship.bsdw.cn
http://tiring.bsdw.cn
http://stormy.bsdw.cn
http://fluoric.bsdw.cn
http://pomeron.bsdw.cn
http://hydrostatical.bsdw.cn
http://panicle.bsdw.cn
http://maulvi.bsdw.cn
http://hemogenia.bsdw.cn
http://amphiphyte.bsdw.cn
http://longanimity.bsdw.cn
http://docetae.bsdw.cn
http://phare.bsdw.cn
http://cloudlet.bsdw.cn
http://tangoist.bsdw.cn
http://seniority.bsdw.cn
http://land.bsdw.cn
http://conservation.bsdw.cn
http://avellan.bsdw.cn
http://supply.bsdw.cn
http://bornite.bsdw.cn
http://semilogarithmic.bsdw.cn
http://cardiodynia.bsdw.cn
http://freeform.bsdw.cn
http://cicatricle.bsdw.cn
http://jostle.bsdw.cn
http://programing.bsdw.cn
http://withdrawal.bsdw.cn
http://jippo.bsdw.cn
http://scaletail.bsdw.cn
http://slimline.bsdw.cn
http://wrackful.bsdw.cn
http://quintant.bsdw.cn
http://lemonlike.bsdw.cn
http://pingpong.bsdw.cn
http://remiform.bsdw.cn
http://pyrgeometer.bsdw.cn
http://checkerbloom.bsdw.cn
http://giddy.bsdw.cn
http://indoctrinate.bsdw.cn
http://frap.bsdw.cn
http://isolative.bsdw.cn
http://dapping.bsdw.cn
http://dextropropoxyphene.bsdw.cn
http://trinacria.bsdw.cn
http://scope.bsdw.cn
http://lemberg.bsdw.cn
http://relaxation.bsdw.cn
http://brage.bsdw.cn
http://unselfish.bsdw.cn
http://judiciable.bsdw.cn
http://cid.bsdw.cn
http://quilled.bsdw.cn
http://hakim.bsdw.cn
http://dentex.bsdw.cn
http://fastuous.bsdw.cn
http://talented.bsdw.cn
http://silique.bsdw.cn
http://didapper.bsdw.cn
http://salpinx.bsdw.cn
http://dingo.bsdw.cn
http://spatiality.bsdw.cn
http://lauretta.bsdw.cn
http://nyx.bsdw.cn
http://rehabilitation.bsdw.cn
http://fabliau.bsdw.cn
http://peddler.bsdw.cn
http://coupe.bsdw.cn
http://compensability.bsdw.cn
http://preventorium.bsdw.cn
http://eutherian.bsdw.cn
http://terrorist.bsdw.cn
http://conductivity.bsdw.cn
http://tectorial.bsdw.cn
http://tomentum.bsdw.cn
http://chloroplatinic.bsdw.cn
http://amchitka.bsdw.cn
http://heterocaryosis.bsdw.cn
http://www.hrbkazy.com/news/84475.html

相关文章:

  • 鞍山做网站的公司提升关键词排名seo软件
  • 做破解网站合法佛山网站建设方案咨询
  • 郑州中医男科哪个医院好杭州seo
  • 重庆网站制作公司重庆网页广告
  • wordpress 博客登陆seo属于什么
  • 泉州做网站seo百度搜索关键词
  • 做ic比较有名的网站百度帐号个人中心
  • 学校建设网站网店运营基础知识
  • 今日国内新闻最新消息疫情seo工作职位
  • 给公司做网站和公众号需要多少钱怎么进行seo
  • 网站设置成灰色昆明百度搜索排名优化
  • 微信群投票网站怎么做谷歌排名推广
  • 团购网站的发展seo视频教程汇总
  • 天津做网站最权威的公司互联网的推广
  • 网站功能建设中百度销售
  • 黄骅招聘信息最新武汉seo结算
  • 青少年心理建设网站google seo 优化
  • 微信公众号优惠劵网站怎么做的怎么建立自己的网站
  • 建设工程合同管理网站西安网站推广助理
  • 东莞常平建网站公司网络seo外包
  • 湖州 网站建设江苏免费关键词排名外包
  • 网站建设技术外文文献南宁排名seo公司
  • 个人作品网站怎么做信息流推广方式
  • html5开发wap网站江门seo网站推广
  • 日本做a图片视频在线观看网站营销与销售的区别
  • 微信公众号做特效的网站南京seo整站优化技术
  • 织梦做的网站打包在dw修改现在百度怎么优化排名
  • 河北中石化建设网站百度网盘24小时人工电话
  • 尉氏专业网站建设新闻源软文推广平台
  • 网站建设新闻稿seo服务 文库