Home > Back-end >  Controller GetMapping/RequestMapping not working
Controller GetMapping/RequestMapping not working

Time:09-07

I'm practicing my springboot knowledge so I'm trying to create a simple Todo Application. When I run my main app at localhost:8080/tasks/list, I'm getting a Whitelabel error page even If I configure the correct routing for my html file. I'm using JSP at this time, I also created a thymeleaf version of this but still I'm getting the same error. Thanks!

enter image description here

MainApp.java

package task.springboot.todo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class TodoappOracleApplication {

    public static void main(String[] args) {
        SpringApplication.run(TodoappOracleApplication.class, args);
    }

}

TaskController.java

package task.springboot.todo.controller;

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




@Controller
@RequestMapping("/tasks")
public class TaskController {

    @GetMapping("/list")
    public String showTodoList() {
        
        
        return "todo-list";
    }
    
}

todo-list.jsp

<!DOCTYPE html>
<html>
    <head>
        <title> Todo Application </title>
    </head>
    <body>
        <h2>Welcome to Todo Application</h2>
    
    </body>
</html>

pom.xml

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.3</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>task.springboot.todo</groupId>
    <artifactId>todoapp_oracle</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>todoapp_oracle</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>17</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-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>com.oracle.database.jdbc</groupId>
            <artifactId>ojdbc8</artifactId>
            <scope>runtime</scope>
        </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>

application.properties

#
#
#
#
# Oracle Database Datasource
#
#
spring.datasource.url=jdbc:oracle:thin:@localhost:1521:xe
spring.datasource.username=system
spring.datasource.password=password

#
#
#
#

CodePudding user response:

Please add thymeleaf dependency to the pom.xml

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

and change the file extension from .jsp to .html (todo-list.html) and place it under path src/main/resources/templates

CodePudding user response:

please add this line to application.properities :

spring.mvc.view.prefix=/jsp_file_directory/

spring.mvc.view.surfix=.jsp
  • Related