Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring boot app showing 404 for index.html

Tags:

spring-boot

I have a Spring boot application and a static index.html file located in src/main/resources/static

my controller is straight forward and looks like this

@Controller
@Log4j
public class StartController {

    @Autowired
    OwnerRepository ownerRepository;

    @RequestMapping("/")
    public String index() {
        return "index";


    }

}

my only configuration is the main one and it only has the @SpringBootApplication Im getting 404 when I hit the URL, as per my understanding no further configuration is needed by the way in the logs on the startup im seeing the following

URI Template variables for request [/index] are {}

here is my POM

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.datasol</groupId>
    <artifactId>alquifacil</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>

    <name>AlquiFacil</name>
    <description>spring boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.1.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-mongodb</artifactId>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.16.6</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>
like image 355
naoru Avatar asked Sep 18 '25 23:09

naoru


1 Answers

On your pom.xml i didn't see any template engine like Thymeleaf, Velocity ecc but you have spring-boot-starter-web, so basically you resource folder its configurated, but you should put your file index.html on templates folder. Static folder serve to contain your asset files.

If you are working local, try: localhost:8080/ or localhost:8080/alquifacil/ assuming you are using port 8080 or add a template engine dependency in pom.xml like Thymeleaf

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

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!