JAVA-11420: Dissolve spring-boot-1 and spring-boot-2 inside (#12122)

spring-boot-modules
This commit is contained in:
freelansam
2022-04-28 22:45:45 +05:30
committed by GitHub
parent 01e30fef42
commit 4690807a09
56 changed files with 85 additions and 1203 deletions
@@ -0,0 +1,35 @@
package com.baeldung.actuator;
import org.springframework.boot.actuate.endpoint.Endpoint;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
@Component
public class CustomEndpoint implements Endpoint<List<String>> {
@Override
public String getId() {
return "customEndpoint";
}
@Override
public boolean isEnabled() {
return true;
}
@Override
public boolean isSensitive() {
return true;
}
@Override
public List<String> invoke() {
// Custom logic to build the output
List<String> messages = new ArrayList<>();
messages.add("This is message 1");
messages.add("This is message 2");
return messages;
}
}
@@ -0,0 +1,23 @@
package com.baeldung.actuator;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component;
@Component("myHealthCheck")
public class HealthCheck implements HealthIndicator {
@Override
public Health health() {
int errorCode = check(); // perform some specific health check
if (errorCode != 0) {
return Health.down().withDetail("Error Code", errorCode).build();
}
return Health.up().build();
}
public int check() {
// Our logic to check health
return 0;
}
}
@@ -0,0 +1,28 @@
package com.baeldung.actuator;
import org.springframework.boot.actuate.metrics.CounterService;
import org.springframework.stereotype.Service;
import java.util.Arrays;
@Service
public class LoginServiceImpl {
private final CounterService counterService;
public LoginServiceImpl(CounterService counterService) {
this.counterService = counterService;
}
public boolean login(String userName, char[] password) {
boolean success;
if (userName.equals("admin") && Arrays.equals("secret".toCharArray(), password)) {
counterService.increment("counter.login.success");
success = true;
} else {
counterService.increment("counter.login.failure");
success = false;
}
return success;
}
}
@@ -0,0 +1,13 @@
package com.baeldung.actuator;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringBoot {
public static void main(String[] args) {
SpringApplication.run(SpringBoot.class, args);
}
}
@@ -3,3 +3,24 @@ feature.new.foo=Y
last.active.after=2018-03-14T00:00:00Z
first.active.after=2999-03-15T00:00:00Z
logging.level.org.flips=info
#actuator properties
### server port
server.port=8080
#port used to expose actuator
management.port=8081
#CIDR allowed to hit actuator
management.address=127.0.0.1
# Actuator Configuration
# customize /beans endpoint
endpoints.beans.id=springbeans
endpoints.beans.sensitive=false
endpoints.beans.enabled=true
# for the Spring Boot version 1.5.0 and above, we have to disable security to expose the health endpoint fully for unauthorized access.
# see: https://docs.spring.io/spring-boot/docs/1.5.x/reference/html/production-ready-monitoring.html
management.security.enabled=false
endpoints.health.sensitive=false
# customize /info endpoint
info.app.name=Spring Sample Application
info.app.description=This is my first spring boot application
info.app.version=1.0.0