Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot Web starter views location

I tried to make a simple Spring Boot web application:

POM:

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.0.0.BUILD-SNAPSHOT</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

Main class:

@ComponentScan(basePackages={"controller"})
@Import(MvcConfig.class)
@EnableAutoConfiguration
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

the controller:

@Controller
@RequestMapping("/home")
public class HomeController {
    @RequestMapping("/hello")
    @ResponseBody
    public String hello(){
        return "hello";
    }
    @RequestMapping("/helloView")
    public String helloView(){
        return "homeView";
    }
}

Also under src/main i got

src
   -main
       -resources
            applicaion.properties
       -webapp
            -WEB-INF
                 -jsp
                     -homeView.jsp

In application.properties I got:

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

The rest endpoint /home/hello works, but the other one can't open the jsp. In the log i got

Looking up handler method for path /WEB-INF/jsp/homeView.jsp
Did not find handler method for [/WEB-INF/jsp/homeView.jsp]

Where should I put the views so the app can find them?

like image 457
Evgeni Dimitrov Avatar asked Mar 29 '14 12:03

Evgeni Dimitrov


People also ask

What is included in spring boot starter web?

Starter of Spring web uses Spring MVC, REST and Tomcat as a default embedded server. The single spring-boot-starter-web dependency transitively pulls in all dependencies related to web development. It also reduces the build dependency count.

Where do html files go in spring boot?

In the index. html file we have a link that invokes a response from the web application. The file is located in the src/main/resources/static directory, which is a default directory where Spring looks for static content.

Does spring boot starter web include Jackson?

Auto-configuration for Jackson is provided and Jackson is part of spring-boot-starter-json . When Jackson is on the classpath an ObjectMapper bean is automatically configured. Several configuration properties are provided for customizing the configuration of the ObjectMapper .

Which property should be set in spring boot for resolving view name?

jsp . The ResourceBundleViewResolver inspects the ResourceBundle identified by the basename, and for each view it is supposed to resolve, it uses the value of the property [viewname].


1 Answers

Thanks to geoand's answer I added

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

to the pom and it worked.

like image 89
Evgeni Dimitrov Avatar answered Oct 05 '22 12:10

Evgeni Dimitrov