【发布时间】:2014-12-31 18:14:24
【问题描述】:
我正在尝试调整我的应用程序配置以设置 ETag 支持。
我刚刚检查了this SO 问题,所以让我说一下我的代码与它的不同之处:
- 我不使用任何 xml 配置文件。
- 我为系统的各个方面使用了不同的配置类。我的
WebConfig看起来像这样:
@Configuration
@EnableAutoConfiguration
@ComponentScan(basePackages = { "xxx", "yyy" })
public class WebConfig extends WebMvcConfigurerAdapter {
@Bean
public Filter shallowETagHeaderFilter() {
return new ShallowEtagHeaderFilter();
}
...
}
- 我的 SecurityConfig 如下所示:
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
...
@Override
protected void configure(final HttpSecurity http) throws Exception {
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and().exceptionHandling()
.authenticationEntryPoint(authenticationEntryPoint())
.and().authorizeRequests()
.antMatchers(HttpMethod.GET, "/**").authenticated()
.antMatchers(HttpMethod.POST, "/**").authenticated()
.antMatchers(HttpMethod.HEAD, "/**").authenticated()
.and().csrf().disable()
.addFilterBefore(authenticationTokenProcessingFilter(), UsernamePasswordAuthenticationFilter.class);
}
}
- 我还有一个初始化类,它是空的:
@Order(value=1)
public class SecurityWebAppInitializer extends AbstractSecurityWebApplicationInitializer {
}
我没有看到 ShallowEtagHeaderFilter 被添加到默认链或任何其他地方,我如何在此设置中使用它?
【问题讨论】:
-
你的问题/问题是? Spring Boot 应该会自动添加过滤器。您的初始化程序未使用,因此不会执行或添加任何内容。 Spring Boot 已启用 Spring Security,因此不需要您的
@EnableWebSecurity。 -
好吧,在这种情况下它不会自动设置它。如何修改我的初始化程序以启动 ShallowEtagHeaderFilter?
-
你不能因为初始化程序在 Spring Boot 应用程序中没有做任何事情。
-
我真的没有关注。所以我不应该使用初始化器?
-
您是否阅读了 Spring Boot 文档并查看了示例?它会创建一个可执行的 jar/war,或者如果您想将其部署为一个 war,而不是一个可执行的 jar 文件,则需要一个自定义初始化程序。
标签: spring annotations spring-boot servlet-filters etag