0

I am trying to adapt the Controller example on the Spring Boot website. Unfortunately I've got the error 404 when I am trying to access the localhost:8080/NewFile URL

my EcomercController.java :

package com.techprimers.jpa.springjpahibernateexample.web;

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

@Controller
public class EcomercController {
    @RequestMapping(value = "/NewFile", method = RequestMethod.GET)
    public String NewFile(){
         return "NewFile";
    }
}

and also i added this dependency in my porm.xml

 <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>

and my path package

com.exemple

----- com.exemple.web.EcomercController.java

com.exemple.SpringJpaHibernateExampleApplication

and my file NewFile.html in

resources->static->NewFile.html

2
  • Can you post the link of that example you are trying to replicate? Commented Dec 10, 2019 at 11:42
  • is it in the same package hierarchy as the class annotating SpringApplication? Commented Dec 10, 2019 at 11:43

4 Answers 4

1

Place your html file in either of these-

src/main/resources/resources/index.html
src/main/resources/static/index.html 
src/main/resources/public/index.html

And since you opted for this-

src/main/resources/resources/index.html

Then place inside templates.

Sign up to request clarification or add additional context in comments.

Comments

0

Your html file should be inside templates folder

resources->templates->NewFile.html

Read Spring Boot Serving static content to understand the resource mapping.

Comments

0

Move your Html file into resources->templates folder

Comments

0

Make sure in the applicaton configuration (under the resources folder) you have no context mapping. I think the default is "/api", in which case you'd need to access the URL as:

localhost:8080/api/NewFile

recommended: don't capitalize your URIs. use new-file or newfile instead.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.