Spring “春季安全”;对等方重置连接:套接字写入错误“;在处理JSF资源请求时
我正在开发一个基于Spring、JPA/Hibernate和Primefaces的webapp,其中包含Spring的注释配置(无application context.xml)。我有一个基于XML配置的功能性webapp,但我想在没有XML配置的情况下复制同一个应用程序 我对配置进行了更改,看起来一切正常,但当我部署应用程序时,它会崩溃,并显示以下消息:Spring “春季安全”;对等方重置连接:套接字写入错误“;在处理JSF资源请求时,spring,jsf,spring-security,resources,Spring,Jsf,Spring Security,Resources,我正在开发一个基于Spring、JPA/Hibernate和Primefaces的webapp,其中包含Spring的注释配置(无application context.xml)。我有一个基于XML配置的功能性webapp,但我想在没有XML配置的情况下复制同一个应用程序 我对配置进行了更改,看起来一切正常,但当我部署应用程序时,它会崩溃,并显示以下消息: ClientAbortException: java.net.SocketException: Connection reset by
ClientAbortException: java.net.SocketException: Connection reset by peer: socket write error
at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:406)
at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:480)
at org.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:366)
at org.apache.catalina.connector.OutputBuffer.writeBytes(OutputBuffer.java:431)
at org.apache.catalina.connector.OutputBuffer.write(OutputBuffer.java:419)
at org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:91)
at org.springframework.security.web.context.SaveContextOnUpdateOrErrorResponseWrapper$SaveContextServletOutputStream.write(SaveContextOnUpdateOrErrorResponseWrapper.java:457)
at java.nio.channels.Channels$WritableByteChannelImpl.write(Unknown Source)
at com.sun.faces.application.resource.ResourceHandlerImpl.handleResourceRequest(ResourceHandlerImpl.java:283)
at javax.faces.application.ResourceHandlerWrapper.handleResourceRequest(ResourceHandlerWrapper.java:125)
at org.primefaces.application.resource.PrimeResourceHandler.handleResourceRequest(PrimeResourceHandler.java:87)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:591)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
//more error lines ...
真的,我不知道为什么会发生这种情况,但我认为这可能是SpringSecurity配置,这是我的SecurityContext.java
//imports
@Configuration
@EnableWebSecurity
public class SecurityContext extends WebSecurityConfigurerAdapter {
@Autowired
@Qualifier("userDetailsService")
UserDetailsService userDetailsService;
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/private/**").access("isAuthenticated()")
.antMatchers("/public/**").permitAll()
.antMatchers("/javax.faces.resource/**").permitAll()
.and()
.formLogin().loginPage("/public/index.xhtml")
.and().logout().logoutUrl("/logout").logoutSuccessUrl("/").invalidateHttpSession(true);
}
}
UserDetailsService
的实现是我的AuthenticationService
类
@Service("userDetailsService")
public class AuthenticationService implements UserDetailsService {
//loadUserByUsername implementation works fine in the XML based project
}
import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer;
public class SecurityWebApplicationInitializer extends AbstractSecurityWebApplicationInitializer {
}
此外,我还有一个SecurityWebApplicationInitializer
类
@Service("userDetailsService")
public class AuthenticationService implements UserDetailsService {
//loadUserByUsername implementation works fine in the XML based project
}
import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer;
public class SecurityWebApplicationInitializer extends AbstractSecurityWebApplicationInitializer {
}
这是我的WebAppConfiguration
类,请参阅SecurityContext
类导入
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.web.app")
@Import({ SecurityContext.class })
public class WebAppConfiguration extends WebMvcConfigurerAdapter {
@Bean
public InternalResourceViewResolver jsfViewResolver() {
InternalResourceViewResolver bean = new InternalResourceViewResolver();
bean.setPrefix("/");
bean.setSuffix(".xhtml");
return bean;
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
}
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
}
在faces-config.xml中输入解析程序定义
<application>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>
谢谢 删除@EnableWebMvc
注释。用于启用SpringMVC模块,如果您对路径不太小心,它可能与JSF冲突。其他一切看起来都正常。谢谢@XtremeBiker,但不起作用。请删除@EnableWebMvc
注释。用于启用SpringMVC模块,如果您对路径不太小心,它可能与JSF冲突。其他一切看起来都很好。谢谢@XtremeBiker,但不起作用。