2017-01-19 97 views
-1
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); 
    } 
} 

控制器:彈簧引導白色標籤錯誤頁面

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","[email protected]")); 
     return employeesList; 
    } 
} 

豆:

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:

<?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> 

錯誤: 白色標籤錯誤頁面

此應用程序沒有顯式映射/錯誤,因此您將此視爲後備。

Thu Jan 19 15:27:39 IST 2017 有一個意外的錯誤(type = Not Found,status = 404)。 無

消息我是新來春boot.plese幫我解決這個錯誤

回答

0

我認爲這個問題與@ComponentScan和包裝有關。如果未定義特定的包,則將從聲明此批註的類的包中進行掃描。嘗試從改變你的SpringbootdemoApplication類的包:

package com.example.demo; 

...這一個:

package com.example; 
0

你不再需要@ComponentScan因爲它已經進入@SpringBootApplication

在另一邊,錯誤與您沒有提供回退到應用程序的事實有關root context /

0

這是因爲Spring Boot掃描程序包com.example.demo下的程序包。 將EmployeeController的包名從com.example.controller更改爲com.example.demo.controller