osa*_*oub 4 java spring spring-boot
我开始使用spring boot,运行一个demo spring web starter项目,我通过调用http:// localhost:8080/mappings和http:// localhost:8080/health来检查弹簧执行器功能 ...它给了我"Whitelabel错误页面"...日志没有显示任何内容
该项目是一个非常简单的启动应用程序,在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);
}
}
Run Code Online (Sandbox Code Playgroud)
休息控制器:
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;
}
.
.
.
.
}
Run Code Online (Sandbox Code Playgroud)
应用属性:
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
Run Code Online (Sandbox Code Playgroud)
的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>
Run Code Online (Sandbox Code Playgroud)
问题是什么?如何使日志更具描述性
Myk*_*nko 16
从Spring Boot 2.0.0.RELEASE开始,所有端点的默认前缀都是/actuator
如此.如果你想检查一个应用程序的运行状况,你应该去/actuator/health
要通过HTTP提供执行器端点,需要同时启用和公开.
默认情况下:
只有/health和/info端点被暴露.
所有端点但/shutdown已启用(仅显示/ health和/ info)
要公开所有端点,您必须将以下行添加到application.properties:
management.endpoints.web.exposure.include=*
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3819 次 |
| 最近记录: |