最近項目完成后打包成war發(fā)布到服務器遇到訪問應用404問題,用的是tomcat8.5,錯誤信息如下:
o.s.b.w.servlet.support.ErrorPageFilter??:?Cannot?forward?to?error?page?for?request?[/login]?as?the?response?has?already?been?committed.?As?a?result,?the?response?may?have?the?wrong?status?code.?If?your?application?is?running?on?WebSphere?Application?Server?you?may?be?able?to?resolve?this?problem?by?setting?com.ibm.ws.webcontainer.invokeFlushAfterService?to?false項目是springboot+security+mybatis,ide 用的idea,打包方式用的是build菜單中的Build Artifactissecurity配置protected?void?configure(HttpSecurity?http)?throws?Exception?{
????http.authorizeRequests()
????????????????//處理preflight請求
????????????????//.requestMatchers(CorsUtils::isPreFlightRequest).permitAll()
????????????????.antMatchers("/user/login").permitAll()
????????????????.antMatchers("/login").permitAll()
????????????????.antMatchers("/login/error").permitAll()
????????????????.anyRequest().authenticated()
????????????????.and()
????????????????//設置登錄頁
????????????.formLogin()
????????????????//設置登錄成功頁
????????????????.loginPage("/login")
????????????????.successHandler(securityLoginSuccessHandler)
????????????????.failureHandler(securityLoginFailureHandler)
????????????????.and()
????????????.logout()
????????????????.logoutUrl("/logout")
????????????????.logoutSuccessHandler(securityLogoutSuccessHandler)
????????????????.deleteCookies("JSESSIONID")
????????????????.and()
????????????.sessionManagement()
????????????????//session超時處理
????????????????.invalidSessionUrl("/login/invalid")
????????????????.maximumSessions(1)
????????????????//老用戶被踢出后操作
????????????????.expiredSessionStrategy(new?SecurityExpiredSessionStrategy());
????http.csrf().disable()
????????????.exceptionHandling().accessDeniedHandler(securityAccessDeniedHandler);
}loginpage的“/login”配置如下:@RequestMapping("/login")
public?String??showLogin()?throws?IOException?{
????System.out.println("調(diào)用loginController的登錄方法");
????return?"index.html#/login";
}在啟動類加入配置:public?class?KpApplication?extends?SpringBootServletInitializer?{
????public?static?void?main(String[]?args)?{
????????SpringApplication.run(KpApplication.class,?args);
????}
????@Bean
????public?ErrorPageFilter?errorPageFilter()?{
????????return?new?ErrorPageFilter();
????}
????@Bean
????public?FilterRegistrationBean?disableSpringBootErrorFilter(ErrorPageFilter?filter)?{
????????FilterRegistrationBean?filterRegistrationBean?=?new?FilterRegistrationBean();
????????filterRegistrationBean.setFilter(filter);
????????filterRegistrationBean.setEnabled(false);
????????return?filterRegistrationBean;
????}
}
重新打包發(fā)布到linux服務器,新的錯誤信息為:?o.s.b.d.LoggingFailureAnalysisReporter? ?:?***************************APPLICATION FAILED TO START***************************Description:The bean 'errorPageFilter', defined in org.springframework.boot.web.servlet.support.ErrorPageFilterConfiguration, could not be registered. A bean with that name has already been defined in com.kpzdh.kp.KpApplication and overriding is disabled.Action:Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true然后在yml配置中加入配置:spring:
??jmx:
????default-domain:?demo
??datasource:
????driver-class-name:?com.mysql.cj.jdbc.Driver
????url:?jdbc:mysql://localhost:3306/demo?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=GMT%2B8
????username:?root
????password:?root
??main:
????allow-bean-definition-overriding:?true
????
如上配置之后,兩個錯誤信息都沒有出現(xiàn)了,但是還是404,查看日志,"/login"路徑的"調(diào)用loginController的登錄方法"已經(jīng)輸出了,
但是瀏覽器控制臺中,/login路徑還是404,請問該如何解決呢?這個問題已經(jīng)困擾很久了,希望大家能幫幫我,萬分感謝!
3 回答

添加回答
舉報
0/150
提交
取消