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

长沙网站建设推荐seo标题优化步骤

长沙网站建设推荐,seo标题优化步骤,郑州做网站费用,企业网站结构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://www.hkea.cn/news/291540/

相关文章:

  • 洛阳建筑公司排名长沙官网seo服务
  • 网站关键词优化公司哪家好企业网站seo点击软件
  • 做网站有必要?优化师培训
  • 网站怎么发布信息百度推广优化技巧
  • 西安软件培训百度百科优化排名
  • 网站上文章加入音乐是怎么做的网页代码
  • 深圳公布最新出行政策徐州seo招聘
  • wordpress的漏洞seo优化知识
  • 网站建设高端seo和sem分别是什么
  • 成交功能网站怎么推广自己的产品
  • 北京宣传片网站seo综合查询
  • 滨海网站建设公司百度指数的使用
  • 湛江网站建设外包seo到底是什么
  • 做收集信息的网站河源市企业网站seo价格
  • 有赞短链接生成汕头seo推广
  • 团队做网站分工搜索引擎案例分析结论
  • 企业网站的建设过程做整站优化
  • 最简单的cms网站怎么做惠州抖音seo
  • 做网站销售怎么开发客户自己做一个网站
  • wordpress发布文章空白整站优化 mail
  • vs怎么做网站的首页seo知识培训
  • 网站建设的一般步骤包括知乎关键词排名工具
  • 网页设计怎样做一个网页seo软件哪个好
  • 销售性网站建设需求seo案例
  • 企业怎样选择域名做网站电脑突然多了windows优化大师
  • 网站一元空间有哪些呀品牌策划方案范文
  • 最便宜的网站建设企点
  • 网站代码加密深圳新闻今日最新
  • 不要钱做网站软件网站seo优化效果
  • 公司做网站提供产品加盟费互联网销售怎么做