0

For some special reason, I have to support JSP files in two different locations.

Currently I wrote the following configuration:

@Configuration
public class JSPConfig {

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

    @Bean
    public InternalResourceViewResolver viewResolver2() {
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
        viewResolver.setPrefix("/webpage/");
        viewResolver.setSuffix(".jsp");
        viewResolver.setOrder(2);
        return viewResolver;
    }

}

But it does not work. The 1st InternalResourceViewResolver is for JSP file in my project, it works without any problem. The 2nd one is for JSP file in one 3rd party jar with the following path {jarfilename}\org\apache\jsp\webpage\modules\gen. And the path for 3rd party jar file in final war file is {warfilename}\WEB-INF\lib\. I use the JSP file as modules/gen/{some_jsp_name_without_suffix} in one controller. Unfortunately the JSP file in the 3rd can not be located.

Through debugging step by step, I noticed that the reason is that it never tries to locate and match the 2nd InternalResourceViewResolver under current configuration. It tries to match the 1st view resolver, failed. It tries to match some .ftl view resolver, failed.

Could any one give me a hand? Does Spring boot support locating JSP files under two different paths?

Thanks very much.

ygor
  • 1,726
  • 1
  • 11
  • 23
Jiang
  • 1
  • No it doesn't. And that has nothing to do with Spring Boot but how the `UrlViewResovler` works internally. – M. Deinum Nov 22 '18 at 13:53
  • @M.Deinum you mean there is no way to work around? – Jiang Nov 22 '18 at 14:03
  • @Jiang Have you looked at the answer over [here](https://stackoverflow.com/questions/5013917/can-i-serve-jsps-from-inside-a-jar-in-lib-or-is-there-a-workaround) – mallikarjun Nov 22 '18 at 14:14
  • You could extend the `InternalResourceViewResolver` and check if the actual resolved URL would exist. But this could be very bad for performance. – M. Deinum Nov 22 '18 at 14:31

0 Answers0