renaming the project
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package org.baeldung.endpoints;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.Endpoint;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class CustomEndpoint implements Endpoint<List<String>> {
|
||||
|
||||
public CustomEndpoint() {
|
||||
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return "customEndpoint";
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isSensitive() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public List<String> invoke() {
|
||||
// Your logic to display the output
|
||||
List<String> messages = new ArrayList<String>();
|
||||
messages.add("This is message 1");
|
||||
messages.add("This is message 2");
|
||||
return messages;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package org.baeldung.endpoints;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.actuate.endpoint.AbstractEndpoint;
|
||||
import org.springframework.boot.actuate.endpoint.Endpoint;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ListEndpoints extends AbstractEndpoint<List<Endpoint>> {
|
||||
private List<Endpoint> endpoints;
|
||||
|
||||
@Autowired
|
||||
public ListEndpoints(List<Endpoint> endpoints) {
|
||||
super("listEndpoints");
|
||||
this.endpoints = endpoints;
|
||||
}
|
||||
|
||||
public List<Endpoint> invoke() {
|
||||
return this.endpoints;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package org.baeldung.endpoints;
|
||||
|
||||
import org.springframework.boot.actuate.health.Health;
|
||||
import org.springframework.boot.actuate.health.HealthIndicator;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class MyHealthCheck implements HealthIndicator {
|
||||
|
||||
public Health health() {
|
||||
int errorCode = check(); // perform some specific health check
|
||||
if (errorCode != 0) {
|
||||
return Health.down().withDetail("Error Code", errorCode).withDetail("Description", "You custom MyHealthCheck endpoint is down").build();
|
||||
}
|
||||
return Health.up().build();
|
||||
}
|
||||
|
||||
public int check() {
|
||||
// Your logic to check health
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package org.baeldung.main;
|
||||
|
||||
import org.baeldung.service.LoginService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan({ "org.baeldung.endpoints", "org.baeldung.service", "org.baeldung.monitor.jmx" })
|
||||
public class SpringBootActuatorApplication {
|
||||
|
||||
@Autowired
|
||||
private LoginService service;
|
||||
|
||||
@RequestMapping("/")
|
||||
String home() {
|
||||
service.login("admin", "admin".toCharArray());
|
||||
return "TADA!!! You are in Spring Boot Actuator test application.";
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SpringBootActuatorApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.baeldung.monitor.jmx;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.codahale.metrics.JmxReporter;
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
|
||||
@Configuration
|
||||
public class MonitoringConfig {
|
||||
@Autowired
|
||||
private MetricRegistry registry;
|
||||
|
||||
@Bean
|
||||
public JmxReporter jmxReporter() {
|
||||
JmxReporter reporter = JmxReporter.forRegistry(registry).build();
|
||||
reporter.start();
|
||||
return reporter;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package org.baeldung.service;
|
||||
|
||||
public interface LoginService {
|
||||
public boolean login(String userName, char[] password);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package org.baeldung.service;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.actuate.metrics.CounterService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class LoginServiceImpl implements LoginService {
|
||||
|
||||
private CounterService counterService;
|
||||
|
||||
@Autowired
|
||||
public LoginServiceImpl(CounterService counterService) {
|
||||
this.counterService = counterService;
|
||||
}
|
||||
|
||||
public boolean login(String userName, char[] password) {
|
||||
boolean success;
|
||||
if (userName.equals("admin") && "secret".toCharArray().equals(password)) {
|
||||
counterService.increment("counter.login.success");
|
||||
success = true;
|
||||
} else {
|
||||
counterService.increment("counter.login.failure");
|
||||
success = false;
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
}
|
||||
27
spring-boot/src/main/resources/application.properties
Normal file
27
spring-boot/src/main/resources/application.properties
Normal file
@@ -0,0 +1,27 @@
|
||||
management.port=8081
|
||||
management.address=127.0.0.1
|
||||
|
||||
endpoints.shutdown.enabled=true
|
||||
|
||||
endpoints.jmx.domain=Spring Sample Application
|
||||
endpoints.jmx.uniqueNames=true
|
||||
|
||||
##jolokia.config.debug=true
|
||||
##endpoints.jolokia.enabled=true
|
||||
##endpoints.jolokia.path=jolokia
|
||||
|
||||
spring.jmx.enabled=true
|
||||
endpoints.jmx.enabled=true
|
||||
|
||||
## for pretty printing of json when endpoints accessed over HTTP
|
||||
http.mappers.jsonPrettyPrint=true
|
||||
|
||||
## Configuring info endpoint
|
||||
info.app.name=Spring Sample Application
|
||||
info.app.description=This is my first spring boot application G1
|
||||
info.app.version=1.0.0
|
||||
|
||||
## Spring Security Configurations
|
||||
security.user.name=admin1
|
||||
security.user.password=secret1
|
||||
management.security.role=SUPERUSER
|
||||
Reference in New Issue
Block a user