【发布时间】:2021-10-29 05:34:52
【问题描述】:
在我的所有项目中,我都需要相同的 WebSecurityConfig。所以我复制了扩展 WebSecurityConfigurerAdapter 的相同实现。
我喜欢将它添加到我在每个项目中使用的公共库中,并为此创建一个注释。 但是注解类不能有超类。
我试过了:
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Configuration
@EnableWebSecurity
public @interface EnableGlobalSecurity extends WebSecurityConfigurerAdapter {
}
有没有更好的方法来让它工作?我只想通过添加注释或类似内容来添加我的 SecurityConfiguration。
【问题讨论】:
-
如果我理解正确,您是否想要一个通用的安全配置并将其保留为
jar,然后通过使用例如@EnableGlobalSecurity注释任何项目来使用此配置并设置安全性?跨度> -
是的。我在所有项目中都有相同的安全选项(例如,路径需要经过完全身份验证的用户并且所有人都可以访问。
标签: java spring-boot annotations