Obtention d'une erreur de marque blanche pour l'application Spring-boot


utilisateur10153776

Je suis nouveau dans le développement de démarrage Spring s'il vous plaît aidez-moi avec l'erreur suivante

Structure du répertoire (y compris la structure des fichiers importants uniquement)

src
   -main
       -java
           -com.example.handlingformsubmission
               -Greeting.java
               -GreetingController.java
               -HandlingFormSubmissionApplication.java
       -resources
           -templates
               -greeting.html
               -result.html
           -application.properties
   -test
       -java
           -com.example.handlingformsubmission
               -HandlingFormSubmissionApplicationTest.java
   -build.gradle

Lors de l'exécution, j'ai rencontré cette erreur lorsque je l'exécute sur le navigateur

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Wed Mar 11 19:08:44 IST 2020
There was an unexpected error (type=Not Found, status=404).
No message available

et quand je termine ou arrête l'application

Execution failed for task ':HandlingFormSubmissionApplication.main()'.
> Process 'command '/usr/lib/jvm/java-11-amazon-corretto/bin/java'' finished with non-zero exit value 143

Actuellement, j'utilise Springboot version 2.2.2

voici mon code

build.gradle

plugins {
    id 'org.springframework.boot' version '2.2.2.RELEASE'
    id 'io.spring.dependency-management' version '1.0.8.RELEASE'
    id 'java'
    id 'war'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
}

test {
    useJUnitPlatform()
}


ManipulationFormulaireApplication.java

package com.example.handlingformsubmission;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

@ComponentScan(basePackages = {"com.example.handlingformsubmission.greeting"})
@SpringBootApplication
public class HandlingFormSubmissionApplication {

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

}

GreetingController.java


package com.example.handlingformsubmission.greeting;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;

@Controller
public class GreetingController {

    @GetMapping("/greeting")
    public String greetingForm(Model model) {
        model.addAttribute("greeting", new Greeting());
        return "greeting";
    }

    @PostMapping("/greeting")
    public String greetingSubmit(@ModelAttribute Greeting greeting, Model model) {
        model.addAttribute("greeting", greeting);
        return "result";
    }

}

application.properties

server.port=8000

salutation.html

<!DOCTYPE HTML>
<html xmlns:th="https://www.thymeleaf.org">
<head> 
    <title>Getting Started: Handling Form Submission</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
    <h1>Form</h1>
    <form action="#" th:action="@{/greeting}" th:object="${greeting}" method="post">
        <p>Id: <input type="text" th:field="*{id}" /></p>
        <p>Message: <input type="text" th:field="*{content}" /></p>
        <p><input type="submit" value="Submit" /> <input type="reset" value="Reset" /></p>
    </form>
</body>
</html>

résultat.html

<!DOCTYPE HTML>
<html xmlns:th="https://www.thymeleaf.org">
<head> 
    <title>Getting Started: Handling Form Submission</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
    <h1>Result</h1>
    <p th:text="'id: ' + ${greeting.id}" />
    <p th:text="'content: ' + ${greeting.content}" />
    <a href="/greeting">Submit another message</a>
</body>
</html>

Brent Bradburn

Ce n'est pas spécifié dans la question, mais je suppose que vous voulez effectuer un GET http://localhost:8000/greeting

Je ne corrigerai pas votre formulaire, mais le 404 peut être résolu en corrigeant votre @ComponentScan, par exemple...

// wrong: '.greeting' excludes the 'GreetingController'
@ComponentScan(basePackages = {"com.example.handlingformsubmission.greeting"})

// fixed: specifies a valid path that includes the controller
@ComponentScan(basePackages = {"com.example.handlingformsubmission"})

Une fois ce problème résolu, vous pourrez aller de l'avant et résoudre le problème suivant :

Une erreur inattendue s'est produite (type=Erreur de serveur interne, état=500). Une erreur s'est produite lors de l'analyse du modèle (modèle : "ressource de chemin de classe [templates/greeting.html]")


Vous pouvez également résoudre ce problème en supprimant @ComponentScanentièrement - ce n'est pas nécessaire pour ce scénario initial.

Articles connexes


Page d'erreur de la marque blanche de l'application Spring Boot

Griller : J'obtiens une page d'erreur 404 de marque blanche avec mon application Springboot. Je suis en train de coder en dur une liste d'étudiants et ils devraient apparaître comme base de prénom sur la page. J'ai essayé différentes approches avec le modèle m

Page d'erreur de marque blanche Spring boot et AWS RDS

AppleKIdd Nouveau dans l'utilisation de Spring Boot et continuez à recevoir la page d'erreur Whitelabel sur la cartographie L'application.yml I Believe est correct, pour être honnête, je ne sais pas quel est le problème. J'ai généré les classes d'entités via l