0

Why does my SpringBoot SpringMVC application runs well and display on the browser when i run it using a local tomcat server But the application doesnt load on the context path whenever i run it on tomcat embedded server?

Below is the log message i do get whenver i run it on tamcat embedded server

No mapping found for HTTP request with URI [/ccbpas/WEB-INF/views/index/loginform.jsp] in DispatcherServlet with name 'dispatcherServlet'

Below is my application.properties file for the SpringBoot

server.port = 1098
server.servlet.context-path=/ccbpas
spring.datasource.url=jdbc:mysql://localhost:3306/cataloguing
spring.datasource.username=nandom
spring.datasource.password=nandom
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.mvc.view.prefix=/WEB-INF/views/
spring.mvc.view.suffix=.jsp
spring.mvc.static-path-pattern=/resources/**

What could be the problem running this same app on embedded tomcat server whereas, it works fine and displays on the browser whenever i run it using a local tomcat server.

Nandom Gusen
  • 51
  • 1
  • 5
  • See if [this](https://stackoverflow.com/questions/30406186/spring-boot-java-config-no-mapping-found-for-http-request-with-uri-in) helps. – Sabir Khan Oct 23 '18 at 11:21
  • Thanks. I saw the example in this link but i realised that i have to write an annotation class to extend WebMvcConfigurerAdapter. I believe SpringBoot came to simplify development. Isnt there a way to make it work asides creating another annotation configuration class? – Nandom Gusen Oct 23 '18 at 13:54

1 Answers1

0

I later solved this problem by adding this configuration file

@Bean
public ViewResolver viewResolver() {
    InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
    viewResolver.setViewClass(JstlView.class);
    viewResolver.setPrefix("/WEB-INF/views/");
    viewResolver.setSuffix(".jsp");
    return viewResolver;
}

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/resources/**").addResourceLocations("/resources/theme/");
}

@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
    configurer.enable();
}

After this, I added this dependency

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

The file now runs well on an embedded tomcat server. But i believe that SpringBoot has eliminated much configurations. How come we now have write a configuration file in order to achieve this with SpringBoot?

Nandom Gusen
  • 51
  • 1
  • 5