Spring Boot - where to place the jsp files

前端 未结 8 2175
无人及你
无人及你 2020-12-20 15:55

I am trying to develop a new Spring boot application using MVC as a first step to move my existing Spring MVC application to Spring boot.

However, I am facing an is

8条回答
  •  离开以前
    2020-12-20 16:30

    I have gone exactly the same path. Upgrading a jsp, xml-based spring application to spring boot 2. There are few things you need to consider when migrating:

    First remove @EnableWebMvc.

    Second you need @ComponentScan on top of MyFirstAppApplication class.

    Try to read this article, it helped me alot https://htr3n.github.io/2018/12/jsp-spring-boot/

    Third you also need this dependeny together with embed-jasper:

    
    org.apache.tomcat.embed
    tomcat-embed-core
    9.0.22
    
    

    Last but not least this is a shortcut for creating a view handler in java

    spring.mvc.view.prefix=/WEB-INF/jsp/
    spring.mvc.view.suffix:.jsp
    

    and as far as I know it only works in spring boot 2. You can have Java implementation instead and debug it to see if it ever hit that.

    @Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("/WEB-INF/jsp/");
        resolver.setSuffix(".jsp");       
        registry.viewResolver(resolver);
    }
    

    Because in my case for example I didn't even need a specific or default resolver. I had different resolver for each Controller that I had to define in xml/bean and inject in each class.

提交回复
热议问题