diff --git a/actuator-demo.iml b/actuator-demo.iml
deleted file mode 100644
index cdf5921..0000000
--- a/actuator-demo.iml
+++ /dev/null
@@ -1,110 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index f72f1df..09674ee 100644
--- a/pom.xml
+++ b/pom.xml
@@ -25,15 +25,6 @@
-
- org.springframework.boot
- spring-boot-starter-actuator
-
-
- org.springframework.boot
- spring-boot-starter-security
-
-
org.springframework.boot
spring-boot-starter-web
@@ -77,6 +68,18 @@
spring-security-test
test
+
+
+
+ io.springfox
+ springfox-swagger2
+ 2.9.2
+
+
+ io.springfox
+ springfox-swagger-ui
+ 2.9.2
+
diff --git a/spring-boot-docker.iml b/spring-boot-docker.iml
index 890db68..8f0e34d 100644
--- a/spring-boot-docker.iml
+++ b/spring-boot-docker.iml
@@ -25,7 +25,7 @@
-
+
@@ -37,25 +37,11 @@
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -65,9 +51,12 @@
-
+
+
+
+
@@ -75,7 +64,6 @@
-
@@ -92,7 +80,7 @@
-
+
@@ -109,7 +97,27 @@
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/com/neo/DockerApplication.java b/src/main/java/com/neo/DockerApplication.java
index d3a0276..484b981 100644
--- a/src/main/java/com/neo/DockerApplication.java
+++ b/src/main/java/com/neo/DockerApplication.java
@@ -2,7 +2,9 @@ package com.neo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import springfox.documentation.swagger2.annotations.EnableSwagger2;
+@EnableSwagger2
@SpringBootApplication
public class DockerApplication {
diff --git a/src/main/java/com/neo/config/ActuatorSecurityConfig.java b/src/main/java/com/neo/config/ActuatorSecurityConfig.java
deleted file mode 100644
index fbbd609..0000000
--- a/src/main/java/com/neo/config/ActuatorSecurityConfig.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package com.neo.config;
-
-
-import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest;
-import org.springframework.boot.actuate.context.ShutdownEndpoint;
-import org.springframework.boot.autoconfigure.security.servlet.PathRequest;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.security.config.annotation.web.builders.HttpSecurity;
-import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
-
-@Configuration
-public class ActuatorSecurityConfig extends WebSecurityConfigurerAdapter {
-
- /*
- This spring security configuration does the following
-
- 1. Restrict access to the Shutdown endpoint to the ACTUATOR_ADMIN role.
- 2. Allow access to all other actuator endpoints.
- 3. Allow access to static resources.
- 4. Allow access to the home page (/).
- 5. All other requests need to be authenticated.
- 5. Enable http basic authentication to make the configuration complete.
- You are free to use any other form of authentication.
- */
-
- @Override
- protected void configure(HttpSecurity http) throws Exception {
- http
- .authorizeRequests()
- .requestMatchers(EndpointRequest.to(ShutdownEndpoint.class))
- .hasRole("ACTUATOR_ADMIN")
- .requestMatchers(EndpointRequest.toAnyEndpoint())
- .permitAll()
- .requestMatchers(PathRequest.toStaticResources().atCommonLocations())
- .permitAll()
- .antMatchers("/", "/slowApi")
- .permitAll()
- .antMatchers("/**")
- .authenticated()
- .and()
- .httpBasic();
- }
-}
diff --git a/src/main/java/com/neo/controller/DockerController.java b/src/main/java/com/neo/controller/DockerController.java
index 2a995bb..3310c7d 100644
--- a/src/main/java/com/neo/controller/DockerController.java
+++ b/src/main/java/com/neo/controller/DockerController.java
@@ -5,11 +5,11 @@ import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import io.prometheus.client.Counter;
-import java.util.Random;
-import java.util.concurrent.TimeUnit;
+import io.swagger.annotations.*;
+@Api(value = "测试", description = "测试 API", position = 100, protocols = "http")
@RestController
public class DockerController {
// Counter
@@ -21,6 +21,10 @@ public class DockerController {
.labelNames("method").register();
+ @ApiOperation(
+ value = "hello",
+ notes = "打招呼"
+ )
@RequestMapping("/hello")
public String index() {
// Counter
@@ -32,20 +36,13 @@ public class DockerController {
}
+ @ApiOperation(
+ value = "默认",
+ notes = "默认打招呼"
+ )
@GetMapping("/")
public String sayHello(@RequestParam(value = "name", defaultValue = "Guest") String name) {
return "Hello " + name + "!!";
}
- @GetMapping("/slowApi")
- public String timeConsumingAPI(@RequestParam(value = "delay", defaultValue = "0") Integer delay) throws InterruptedException {
- if(delay == 0) {
- Random random = new Random();
- delay = random.nextInt(10);
- }
-
- TimeUnit.SECONDS.sleep(delay);
- return "Result";
- }
-
}
diff --git a/src/main/java/com/neo/health/CustomHealthIndicator.java b/src/main/java/com/neo/health/CustomHealthIndicator.java
deleted file mode 100644
index 81911b3..0000000
--- a/src/main/java/com/neo/health/CustomHealthIndicator.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.neo.health;
-
-import org.springframework.boot.actuate.health.AbstractHealthIndicator;
-import org.springframework.boot.actuate.health.Health;
-import org.springframework.stereotype.Component;
-
-@Component
-public class CustomHealthIndicator extends AbstractHealthIndicator {
-
- @Override
- protected void doHealthCheck(Health.Builder builder) throws Exception {
- // Use the builder to build the health status details that should be reported.
- // If you throw an exception, the status will be DOWN with the exception message.
-
- builder.up()
- .withDetail("app", "Alive and Kicking")
- .withDetail("error", "Nothing! I'm good.");
- }
-}
\ No newline at end of file
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index 59bca2b..88177b1 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -1,23 +1,25 @@
# Logging
-logging.file=app.log
+#logging.file=app.log
# Spring Security default user name and password
-spring.security.user.name=actuator
-spring.security.user.password=actuator
-spring.security.user.roles=ACTUATOR_ADMIN
+#spring.security.user.name=actuator
+#spring.security.user.password=actuator
+#spring.security.user.roles=ACTUATOR_ADMIN
# INFO ENDPOINT CONFIGURATION
-info.app.name=@project.name@
-info.app.description=@project.description@
-info.app.version=@project.version@
-info.app.encoding=@project.build.sourceEncoding@
-info.app.java.version=@java.version@
+#info.app.name=@project.name@
+#info.app.description=@project.description@
+#info.app.version=@project.version@
+#info.app.encoding=@project.build.sourceEncoding@
+#info.app.java.version=@java.version@
# SHUTDOWN ENDPOINT (ShutdownEndpoint)
-management.endpoint.shutdown.enabled=true
+#management.endpoint.shutdown.enabled=true
# HEALTH ENDPOINT
-management.endpoint.health.show-details=always
+#management.endpoint.health.show-details=always
# ENDPOINTS WEB CONFIGURATION
-management.endpoints.web.exposure.include=*
\ No newline at end of file
+#management.endpoints.web.exposure.include=*
+
+logging.level.io.swagger.models.parameters.AbstractSerializableParameter=error
diff --git a/src/main/resources/prometheus.yml b/src/main/resources/prometheus.yml
index 2e82c40..73ef836 100644
--- a/src/main/resources/prometheus.yml
+++ b/src/main/resources/prometheus.yml
@@ -22,7 +22,7 @@ scrape_configs:
- targets: ['127.0.0.1:9090']
- job_name: 'spring-actuator'
- metrics_path: '/actuator/prometheus'
+ metrics_path: '/metrics' # '/actuator/prometheus'
scrape_interval: 5s
static_configs:
- targets: ['HOST_IP:8080']