Skip to content
Advertisement

What do spring.mvc.view.prefix and spring.mvc.view.suffix have to be?

I created a Spring Boot demo app with Maven using Spring Initializr (that’s my almost the very first usage of Spring). It works, but for some reason doesn’t show any pages besides index.html. If I’m right, that’s because of configuration in application.properties, but I just don’t know, what have I add there.

My project’s sources structure:

JavaScript

I tried to add different prefixes and suffixes into application.properties, but nothing works. Just as an example:

JavaScript

Again, index.html opens perfectly.

Maybe, it would be good to show here my dependences too:

JavaScript

That’s an error page:

JavaScript

If my error is really in application.properties, what have I put there?

Advertisement

Answer

With Default Rendering with template

If you are using default “/resources/templates” for rendering view.Spring Boot only includes auto-configuration support for the following templating engines:

  1. FreeMarker
  2. Groovy
  3. Thyme-leaf
  4. Velocity

Example:

Step1:

For using thymeleaf you should add dependency either with gradle and maven Gradle:

JavaScript

OR Maven:

JavaScript

Step2: Add below code with properties file

JavaScript

With MVC support

By default, this handler serves static content from any of /static, /public, /resources, and /META-INF/resources directories that are on the classpath. Since src/main/resources is typically on the classpath by default, we can place any of these directories there.

Only static folder is available for rendering view.You can customise using below code with properties file.By default Spring Boot will serve static content from a folder called /static (or /public or /resources or /META-INF/resources) in the classpath or from the root of the ServletContext. It uses the ResourceHttpRequestHandler from Spring MVC so you can modify that behavior by adding your own WebMvcConfigurerAdapter and overriding the addResourceHandlers method.

JavaScript

More information visit

https://docs.spring.io/spring-boot/docs/1.1.5.RELEASE/reference/htmlsingle/#boot-features-spring-mvc-static-content

https://www.baeldung.com/spring-mvc-static-resources

Advertisement