minor cleanup work

This commit is contained in:
eugenp 2015-05-30 18:22:29 +01:00
parent df2a789fa2
commit be4c05ad2d
8 changed files with 69 additions and 74 deletions

View File

@ -15,7 +15,6 @@
<version>1.2.3.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>

View File

@ -8,28 +8,28 @@ 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 CustomEndpoint() {
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;
}
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;
}
}

View File

@ -9,15 +9,15 @@ import org.springframework.stereotype.Component;
@Component
public class ListEndpoints extends AbstractEndpoint<List<Endpoint>> {
private List<Endpoint> endpoints;
private List<Endpoint> endpoints;
@Autowired
public ListEndpoints(List<Endpoint> endpoints) {
super("listEndpoints");
this.endpoints = endpoints;
}
@Autowired
public ListEndpoints(List<Endpoint> endpoints) {
super("listEndpoints");
this.endpoints = endpoints;
}
public List<Endpoint> invoke() {
return this.endpoints;
}
public List<Endpoint> invoke() {
return this.endpoints;
}
}

View File

@ -7,16 +7,16 @@ import org.springframework.stereotype.Component;
@Component
public class MyHealthCheck implements HealthIndicator {
public Health health() {
int errorCode = check(); // perform some specific health check
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;
}
public int check() {
// Your logic to check health
return 1;
}
}

View File

@ -1,6 +1,5 @@
package org.baeldung.main;
import org.baeldung.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
@ -11,20 +10,20 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
@EnableAutoConfiguration
@ComponentScan({"org.baeldung.endpoints", "org.baeldung.service", "org.baeldung.monitor.jmx"})
@ComponentScan({ "org.baeldung.endpoints", "org.baeldung.service", "org.baeldung.monitor.jmx" })
public class SpringBootActuatorApplication {
@Autowired
private LoginService service;
@RequestMapping("/")
@Autowired
private LoginService service;
@RequestMapping("/")
String home() {
service.login("admin", "admin".toCharArray());
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);
}
public static void main(String[] args) {
SpringApplication.run(SpringBootActuatorApplication.class, args);
}
}

View File

@ -9,9 +9,9 @@ import com.codahale.metrics.MetricRegistry;
@Configuration
public class MonitoringConfig {
@Autowired
@Autowired
private MetricRegistry registry;
@Bean
public JmxReporter jmxReporter() {
JmxReporter reporter = JmxReporter.forRegistry(registry).build();

View File

@ -1,5 +1,5 @@
package org.baeldung.service;
public interface LoginService {
public boolean login(String userName, char[] password);
public boolean login(String userName, char[] password);
}

View File

@ -7,26 +7,23 @@ 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;
}
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;
}
}