简体   繁体   English

弹簧启动-Whitelabel错误页面

[英]spring boot-Whitelabel Error Page

package com.example.demo;

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


@SpringBootApplication(exclude = SecurityAutoConfiguration.class)
@ComponentScan
public class SpringbootdemoApplication {

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

controller: 控制器:

package com.example.controller;
import java.util.ArrayList;
import java.util.List;

import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.example.module.*;


@RestController
public class EmployeeController 
{
    @RequestMapping(value="/getemp", method = RequestMethod.GET)
    public List<Employee> getEmployees() 
    {
        List<Employee> employeesList = new ArrayList<Employee>();
        employeesList.add(new Employee(1,"lokesh","gupta","howtodoinjava@gmail.com"));
        return employeesList;
    }
}

bean: 豆角,扁豆:

package com.example.module;

public class Employee {

    public Employee() {

    }
    public Employee(Integer id, String firstName, String lastName, String email) {
        super();
        this.id = id;
        this.firstName = firstName;
        this.lastName = lastName;
        this.email = email;
    }

    private Integer id;
    private String firstName;
    private String lastName;
    private String email;

    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    public String getFirstName() {
        return firstName;
    }
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }
    public String getLastName() {
        return lastName;
    }
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }

    @Override
    public String toString() {
        return "Employee [id=" + id + ", firstName=" + firstName
                + ", lastName=" + lastName + ", email=" + email + "]";
    }
}

pom.xml: 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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example.demo</groupId>
    <artifactId>springbootdemo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>springbootdemo</name>
    <description>Demo project for Spring Boot</description>

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

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <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-hateoas</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jersey</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.hsqldb</groupId>
            <artifactId>hsqldb</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>

error: Whitelabel Error Page 错误:Whitelabel错误页面

This application has no explicit mapping for /error, so you are seeing this as a fallback. 此应用程序没有针对/ error的显式映射,因此您将其视为后备。

Thu Jan 19 15:27:39 IST 2017 There was an unexpected error (type=Not Found, status=404). Thu Jan 19 15:27:39 IST 2017发生意外错误(类型=未找到,状态= 404)。 No message available 无讯息

i am new to spring boot.plese help me to solve this error 我是spring boot的新手,请帮助我解决此错误

I think the problem is related with the @ComponentScan and the packaging. 我认为问题与@ComponentScan和包装有关。 If specific packages are not defined, scanning will occur from the package of the class that declares this annotation. 如果未定义特定的程序包,则将从声明此批注的类的程序包中进行扫描。 Try to change the package of your class SpringbootdemoApplication from: 尝试从以下位置更改类SpringbootdemoApplication的软件包:

package com.example.demo;

... to this one: ...对此:

package com.example;

you no more need @ComponentScan as it's already into @SpringBootApplication 您不再需要@ComponentScan因为它已经在@SpringBootApplication

on the other side, the error is related to the fact the you didn't provide fall back to the application root context / 另一方面,该错误与您没有提供的事实有关,它会退回到应用程序的root context /

This is because Spring Boot scans the package under package com.example.demo . 这是因为Spring Boot会扫描软件包com.example.demo下的软件包。 Change the package name of EmployeeController from com.example.controller to com.example.demo.controller EmployeeController的程序包名称从com.example.controller更改为com.example.demo.controller

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM