获取“Whitelabel错误页面”运行执行器运行状况和映射网址

时间:2018-03-26 08:34:28

标签: java spring spring-boot

我开始使用弹簧启动,运行一个演示弹簧Web启动项目,我正在通过调用http://localhost:8080/mappingshttp://localhost:8080/health检查弹簧执行器的功能...它给了我“Whitelabel错误页面” ...日志没有显示任何内容

enter image description here

该项目是一个非常简单的启动应用程序,在STS中创建,其中一个@RestController工作正常

主要课程:

@SpringBootApplication
public class DemoApplication {

    public static HashMap<Long,Student> hmStudent;

    public static void main(String[] args) {
        //dummt code
          SpringApplication.run(DemoApplication.class, args);
    }
}

休息控制器:

import java.util.HashMap;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.example.demo.DemoApplication;
import com.example.demo.entities.Student;

@RestController
@RequestMapping(value="/rest/student")
class StudentService{

   @RequestMapping(value="/",method = RequestMethod.GET)
   public HashMap<Long,Student> getAllStudents(){
      return DemoApplication.hmStudent;
   }
.
.
.
.
}

应用程序属性:

spring.datasource.url=jdbc:oracle:thin:@localhost:ibmwas
spring.datasource.username=u
spring.datasource.password=p
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver

的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</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

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

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.0.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-data-rest</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jta-atomikos</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>
        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc8</artifactId>
            <version>12.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-actuator</artifactId>
            <version>2.0.0.RELEASE</version>
        </dependency>
    </dependencies>

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

问题是什么,我怎样才能使日志更具描述性

3 个答案:

答案 0 :(得分:12)

从Spring Boot 2.0.0.RELEASE开始,所有端点的默认前缀为/actuator 因此,如果您想检查应用程序的运行状况,您应该转到/actuator/health

要通过HTTP提供执行器端点,需要同时启用和公开。

默认情况下:

  • 仅公开/health/info个终结点。

  • 所有端点但/shutdown已启用(仅显示/ health和/ info)

要公开所有端点,您必须将以下行添加到application.properties

management.endpoints.web.exposure.include=*

答案 1 :(得分:1)

我有同样的问题。经过一番尝试和错误之后,当我在浏览器上点击http://localhost:8080时,我得到了执行器的输出,这使我进入了HAL浏览器。在HAL的浏览器中,我键入了执行器,将我带到http://localhost:8080/browser/index.html#http://localhost:8080/actuator,这是我在http://localhost:8080/application所寻找的所有详细信息。

请注意,我使用的Spring引导版本是:2.0.6快照。

并且,在application.properties中,我添加了management.security.enabled = false。没有这个,我可能会看到很少的信息。

答案 2 :(得分:0)

spring.mvc.throw-exception-if-no-handler-found=true
spring.resources.add-mappings=false