P
P
parkito2017-01-10 15:37:38
Java
parkito, 2017-01-10 15:37:38

How to properly configure jsp mapping in SpringBoot?

Hello. I am writing a simple mvc application on Spring Boot. I've run into a problem that I can't find a solution for. Please help.
All three mvc modules are written in the project. Problems arise with view.
There is a controller

@RequestMapping(value = "/", method = RequestMethod.GET)
    public String homePage() {
        return "hello";
    }

There is a tuner
@Configuration
@EnableWebMvc
public class AppConfiguration extends WebMvcConfigurerAdapter {

    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }

    @Bean
    public InternalResourceViewResolver viewResolver() {
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setViewClass(org.springframework.web.servlet.view.JstlView.class);
        resolver.setPrefix("/WEB-INF/");
        resolver.setSuffix(".jsp");
        return resolver;
    }

//    @Override
//    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        registry.addResourceHandler("/WEB-INF/").addResourceLocations("/css/");
//    }

    @Bean
    public FilterRegistrationBean filterRegistrationBean() {
        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
        characterEncodingFilter.setEncoding("UTF-8");
        registrationBean.setFilter(characterEncodingFilter);
        return registrationBean;
    }
}

/src/main/webapp/WEB-INF/ contains hello.jsp
<html>
<head>
    <title>Title</title>
</head>
<body>
<h1>Success!!!</h1>
</body>
</html>

Crashes when starting a project
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Tue Jan 10 15:34:42 MSK 2017
There was an unexpected error (type=Not Found, status=404).
/WEB-INF/hello.jsp

I found numerous complaints about this message on the Internet, but not a single solution suited me.
My version of why this happens is that spring cannot display the jsp page because it cannot find it. I don't know how else they (page and spring) can be aggregated, except by using the customizer.
What can be tried in my situation?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evhen, 2017-01-10
@EugeneP2

spring-boot-sample-web-jsp

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question