sundjerBob
sundjerBob

Reputation: 95

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;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;


@ComponentScan("com.itengine")
@EntityScan("com.itengine")
@EnableJpaRepositories("com.itengine.scoretracker.dao.repository")
@SpringBootApplication
public class ScoreTrackerApplication
    extends SpringBootServletInitializer{

    @Override
    protected SpringApplicationBuilder configure(
            SpringApplicationBuilder builder){

        return builder.sources(ScoreTrackerApplication.class);
    }

    public static void main(String[] args) {

        SpringApplication.run(ScoreTrackerApplication.class, args);

    }
}

Thanks in advance!

Upvotes: 1

Views: 1096

Answers (3)

sundjerBob
sundjerBob

Reputation: 95

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

enter image description here

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

Upvotes: 0

David Schilling
David Schilling

Reputation: 2768

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.

Upvotes: 0

Reimeus
Reimeus

Reputation: 159794

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

Upvotes: 2

Related Questions