0
votes

I used spring initializer to create a simple spring boot web project. I have a simple project setup that includes the following dependencies:

compile('org.springframework.boot:spring-boot-starter-jersey')
compile('org.springframework.boot:spring-boot-starter-web')
testCompile('org.springframework.boot:spring-boot-starter-test')

I am using JSP's as my view, so I added the following bean in my configuration:

@Bean

public ViewResolver getViewResolver() {

    InternalResourceViewResolver resolver = new InternalResourceViewResolver();
    resolver.setPrefix("/WEB-INF/jsp/");
    resolver.setSuffix(".jsp");
    return resolver;
}

When I start the app, and go to the home page, I get a 404 error, however, when I add the following JAR to my classpath

compile group: 'org.apache.tomcat.embed', name: 'tomcat-embed-jasper', version: '7.0.77'

it works. I was under the impression that the spring boot starter web dependency included the embedded tomcat, and I didn't need to add it separately?

Here is the main application class that kicks it off:

@SpringBootApplication(scanBasePackages={"com.wsapp"})
@EnableWebMvc
@EnableAutoConfiguration
public class SampleApplication {

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

1 Answers

0
votes

Why you use jersey in you dependencies if you expect to use tomcat?

compile('org.springframework.boot:spring-boot-starter-jersey')

I think spring autoconfiguration simply load jersey configuration. Tomcat is default but only if you don't explicitly add another module in your dependencies. If you want to use tomcat try do drop this dependency.