2

I'm getting 404s returned by spring boot when trying to render jsp files. My maven config has spring-boot-starter-parent version 1.4.0.RELEASE as the version.

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.0.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent> 

I am running the embedded Tomcat servlet container.

I found this SO post spring-boot basic JSP 404 Not Found and set the required spring.mvc.view.prefix and spring.mvc.view.suffix properties in my application.properties file.

Still 404s.

I then found this SO post spring-boot-not-finding-jsp-pages-in-war-file and added the requisite dependencies in my pom file:

<dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-jasper</artifactId>
    <scope>provided</scope>
</dependency>

Still 404s.

On removing the <scope>provided</scope> tag, everything started to work. Thinking this tag may have resulted in a different classpath for spring boot and hence turned on a different feature, I turned on the spring boot configuration report using --debug and diffed the output with and without the scope tag. There was no difference. Both have the following line in the Positive matches section:

WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter#defaultViewResolver matched - @ConditionalOnMissingBean (types: org.springframework.web.servlet.view.InternalResourceViewResolver; SearchStrategy: all) found no beans (OnBeanCondition)

Can anyone explain why it works without the provided scope?

Community
  • 1
  • 1
user783836
  • 3,099
  • 2
  • 29
  • 34
  • What's your packaging option, `jar` or `war`? – Ali Dehghani Sep 15 '16 at 13:13
  • packaging option is `jar` – user783836 Sep 15 '16 at 13:15
  • 2
    jsps require war packaging... This is documented in the reference guide [here](http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-developing-web-applications.html#boot-features-jsp-limitations). – M. Deinum Sep 15 '16 at 13:18
  • switching to `war` makes it work, thanks. that page implies that jsps won't work in a `jar` package inside of Tomcat. so what about dropping the maven `scope` setting makes it suddenly work? – user783836 Sep 15 '16 at 13:41
  • https://github.com/spring-projects/spring-boot/blob/master/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/JspTemplateAvailabilityProvider.java – Ali Dehghani Sep 15 '16 at 13:42
  • AFAIK `ClassUtils.isPresent("org.apache.jasper.compiler.JspConfig", classLoader)` returns `false` when jasper dependency is `provided`, Since the jasper won't be in the packaged jar when it's provided – Ali Dehghani Sep 15 '16 at 13:43
  • 1
    Cheers, thanks. If you want to make your comments the answer I will happily accept them. – user783836 Sep 15 '16 at 14:05

0 Answers0