Cedomir Mijajlovic February 2016

WelcomeController can't find path to index.html

I am working on some WebApplication with SpringBoot MVC pattern. I have four maven projects (DAO project, REST project(there is SpringBoot class for starting application), SERVICE project and CLIENT project). This projects are connected through dependencies.

My problem is with CLIENT project. There I have WelcomeController which is look like this :

package com.itengine.scoretracker.client.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class WelcomeController {

    @RequestMapping("/")
    public String welcome(){
        return "static/html/index.html";
    }
}

And my html's are on this path:

enter image description here

When I relocate my static folder from CLIENT project in REST project on same location, my WelcomeController see index.html and everything works fine.

So please, can somebody help me with this issue, i really need this html's in CLIENT project. I dont have experience with configuration xml's because i learned on course SpringBoot without those xml's.

My web.xml's are empty, they have only this:

<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application    2.3//EN" "java.sun.com/dtd/web-app_2_3.dtd"; > <web-app> <display-name>Archetype Created Web Application</display-name> </web-app>

My main class is like this:

package com.itengine.scoretracker.rest.init;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.boot.orm.jpa.EntityScan;
impo        

Answers


Reimeus February 2016

Move the static folder to src/main/resources so that it ends up deployed on the classpath. The mapping for / can then be removed.


Cedomir Mijajlovic February 2016

Now, like u say @Reimeus, I have this situation:

enter image description here

And that won't working. And what with removing / mapping??


David Schilling February 2016

If your index.html is plain html, your controller is unnecessary.

Just put the index.html in src/main/resources/static.

That's all you need. Spring boot takes care of the rest.

You also don't need a web.xml.

Post Status

Asked in February 2016
Viewed 3,684 times
Voted 7
Answered 3 times

Search




Leave an answer