0

I started a new project using gradle and spring boot and I cannot get JSPs to work. When I perform the request, I only see the error in logs saying

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

I have seen a lot of problems like that on stack overflow already, but most of them were related to invalid xml configuration... which I don't have since I'm using spring boot.

Here's my configuration

build.gradle:

buildscript {
    ext {
        springBootVersion = '1.2.3.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath("io.spring.gradle:dependency-management-plugin:0.5.0.RELEASE")
    }
}

group 'fi.achivi.server'
version '1.0-SNAPSHOT'

apply plugin: 'war'
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'io.spring.dependency-management'

war {
    baseName = 'achivi'
    version = '0.0.1-SNAPSHOT'
}

jar {
    baseName = 'achivi'
    version = '0.0.1-SNAPSHOT'
}

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    compile 'org.springframework.cloud:spring-cloud-starter-eureka:1.0.1.RELEASE',
            'org.springframework.boot:spring-boot-starter-web',
            'org.springframework:spring-webmvc:4.1.6.RELEASE',
            'org.springframework.boot:spring-boot-starter-data-mongodb',
            'org.springframework.cloud:spring-cloud-config-client:1.0.1.RELEASE',
            'jstl:jstl:1.2',

            'commons-validator:commons-validator:1.4.1',

            'org.springframework.security:spring-security-web:4.0.1.RELEASE',
            'org.springframework.security:spring-security-config:4.0.1.RELEASE'

    testCompile 'org.springframework.boot:spring-boot-starter-test',

                'cz.jirutka.spring:embedmongo-spring:1.3.1', //mongodb dependencies
                'de.flapdoodle.embed:de.flapdoodle.embed.mongo:1.48.0'

    providedRuntime 'org.apache.tomcat.embed:tomcat-embed-jasper:8.0.8'
}

application.properties

server.port=80
server.contextPath=

Server

@Configuration
@SpringBootApplication
@EnableMongoRepositories
public class Server {

    public static void main(String[] args) {
        new SpringApplicationBuilder(Server.class).web(true).run(args);
    }

    @Bean
    public MongoTemplate getMongoTemplate() throws Exception{
        Mongo m = new MongoClient("localhost");
        MongoTemplate template = new MongoTemplate(m, "achivi");
        return template;
    }
}

MVC config @Configuration @EnableWebMvc public class WebConfig extends WebMvcConfigurerAdapter {

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

HomeController:

@Controller
@RequestMapping("/")
public class HomeController {

    @RequestMapping
    public String entry() {
        return "home";
    }
}

and then there's the jsp file in /src/main/webapp/WEB-INF/jsp/home.jsp

I try to access the app under http://localhost

based on all the tutorials I have found, this should probably work. But it still doesn't. Any ideas?

Kamil Janowski
  • 1,872
  • 2
  • 21
  • 43

0 Answers0