Spring boot SpringBoot 2.2在请求时仍显示白色标签错误";/*。jsp";

Spring boot SpringBoot 2.2在请求时仍显示白色标签错误";/*。jsp";,spring-boot,spring-mvc,jsp,Spring Boot,Spring Mvc,Jsp,我有一个带有jsp的SpringBoot2.2Web项目 @Configuration @EnableWebMvc @Slf4j public class WebConfig implements WebMvcConfigurer { @Bean public LocaleChangeInterceptor localeChangeInterceptor() { LocaleChangeInterceptor localeChangeInterceptor =

我有一个带有jsp的SpringBoot2.2Web项目

@Configuration
@EnableWebMvc
@Slf4j
public class WebConfig implements WebMvcConfigurer {


    @Bean
    public LocaleChangeInterceptor localeChangeInterceptor() {
        LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor();
        localeChangeInterceptor.setParamName("language");
        return localeChangeInterceptor;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(localeChangeInterceptor());
    }

    @Bean
    public MessageSource messageSource() {
        ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
        messageSource.setBasenames("classpath:i18n/messages");
        messageSource.setDefaultEncoding("UTF-8");
        return messageSource;
    }

    @Bean
    public LocalValidatorFactoryBean getValidator() {
        LocalValidatorFactoryBean bean = new LocalValidatorFactoryBean();
        bean.setValidationMessageSource(messageSource());
        return bean;
    }

    @Bean
    public ViewResolver jspViewResolver() {
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
        viewResolver.setPrefix("/WEB-INF/jsp/");
        viewResolver.setSuffix(".jsp");
        return viewResolver;
    }

}
应用程序属性

spring.mvc.throw-exception-if-no-handler-found = true
GlobalExceptionHandler.java

@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    public static final String DEFAULT_ERROR_VIEW = "error/error";
    public static final String PAGE_NOT_FOUND_ERROR_VIEW = "error/404";


    @ExceptionHandler(NoHandlerFoundException.class)
    public ModelAndView pageNotFoundErrorHandler(HttpServletRequest req, Exception e) {
        if (log.isDebugEnabled()) {
            log.debug("The page [{}] does not exist : {}", req.getRequestURI(), e.getMessage());
        }
        return getMAV(req, e, HttpStatus.NOT_FOUND, PAGE_NOT_FOUND_ERROR_VIEW);
    }


    private ModelAndView getMAV(HttpServletRequest req, Exception e, HttpStatus status, String viewName) {
        ModelAndView mav = new ModelAndView();
        mav.addObject("error", status.getReasonPhrase());
        mav.addObject("exception", e.getMessage());
        mav.addObject("url", req.getRequestURL());
        mav.setStatus(status);
        mav.setViewName(viewName);
        return mav;
    }
}
当我转到localhost:8080/notMapped时,它会工作。它会显示我的错误页面, 但如果我选择localhost:8080/notMapped.jsp,它会显示白色标签错误 我试着把它去掉

@SpringBootApplication(exclude = {ErrorMvcAutoConfiguration.class})
未工作(显示tomcat 404)

试图把

@Configuration
@EnableWebSecurity
@Slf4j
public class WebSecurity extends WebSecurityConfigurerAdapter {

    @Bean
    public AccessDeniedHandler accessDeniedHandler(){
        return new ApplicationAccessDeniedHandler();
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        log.info("Overriding default configure to bypass default login");
        **http
                .authorizeRequests()
                .antMatchers("/*.jsp")
                .denyAll();**

        http
                .authorizeRequests()
                .anyRequest()
                .permitAll();

        http
                .headers()
                .frameOptions()
                .sameOrigin();
    }

}
仅更改了白标签中的错误代码(404->403)

已删除

@EnableWebMvc
它显示了我的404.jsp

但我看到它仍然使用ErrorMvcAutoConfiguration

@EnableWebMvc
它显示了我的404.jsp

但我看到它仍然使用ErrorMvcAutoConfiguration