Polish samples

This commit is contained in:
Stephane Nicoll
2016-12-30 17:57:14 +01:00
parent a19a28062f
commit c903ff46a7
30 changed files with 149 additions and 105 deletions

View File

@@ -17,12 +17,13 @@
package sample.metrics.dropwizard;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Component
@ConfigurationProperties(prefix = "service", ignoreUnknownFields = false)
public class HelloWorldService {
public class HelloWorldProperties {
/**
* Name of the service.
*/
private String name = "World";
public String getName() {
@@ -33,8 +34,4 @@ public class HelloWorldService {
this.name = name;
}
public String getHelloMessage() {
return "Hello " + this.name;
}
}

View File

@@ -19,9 +19,6 @@ package sample.metrics.dropwizard;
import java.util.Collections;
import java.util.Map;
import org.hibernate.validator.constraints.NotBlank;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.metrics.GaugeService;
import org.springframework.context.annotation.Description;
import org.springframework.stereotype.Controller;
@@ -32,32 +29,21 @@ import org.springframework.web.bind.annotation.ResponseBody;
@Description("A controller for handling requests for hello messages")
public class SampleController {
@Autowired
private HelloWorldService helloWorldService;
private final HelloWorldProperties helloWorldProperties;
@Autowired
private GaugeService gauges;
private final GaugeService gauges;
public SampleController(HelloWorldProperties helloWorldProperties, GaugeService gauges) {
this.helloWorldProperties = helloWorldProperties;
this.gauges = gauges;
}
@GetMapping("/")
@ResponseBody
public Map<String, String> hello() {
this.gauges.submit("timer.test.value", Math.random() * 1000 + 1000);
return Collections.singletonMap("message",
this.helloWorldService.getHelloMessage());
}
protected static class Message {
@NotBlank(message = "Message value cannot be empty")
private String value;
public String getValue() {
return this.value;
}
public void setValue(String value) {
this.value = value;
}
return Collections.singletonMap("message", "Hello " +
this.helloWorldProperties.getName());
}
}

View File

@@ -18,8 +18,10 @@ package sample.metrics.dropwizard;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@SpringBootApplication
@EnableConfigurationProperties(HelloWorldProperties.class)
public class SampleDropwizardMetricsApplication {
public static void main(String[] args) throws Exception {