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,11 +17,9 @@
package sample.metrics.redis;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Component
@ConfigurationProperties(prefix = "service", ignoreUnknownFields = false)
public class HelloWorldService {
public class HelloWorldProperties {
private String name = "World";
@@ -33,8 +31,4 @@ public class HelloWorldService {
this.name = name;
}
public String getHelloMessage() {
return "Hello " + this.name;
}
}

View File

@@ -31,14 +31,18 @@ import org.springframework.web.bind.annotation.ResponseBody;
@Description("A controller for handling requests for hello messages")
public class SampleController {
private final HelloWorldProperties helloWorldProperties;
@Autowired
private HelloWorldService helloWorldService;
public SampleController(HelloWorldProperties helloWorldProperties) {
this.helloWorldProperties = helloWorldProperties;
}
@GetMapping("/")
@ResponseBody
public Map<String, String> hello() {
return Collections.singletonMap("message",
this.helloWorldService.getHelloMessage());
return Collections.singletonMap("message", "Hello " +
this.helloWorldProperties.getName());
}
protected static class Message {

View File

@@ -24,11 +24,13 @@ import org.springframework.boot.actuate.metrics.export.MetricExportProperties;
import org.springframework.boot.actuate.metrics.jmx.JmxMetricWriter;
import org.springframework.boot.actuate.metrics.repository.redis.RedisMetricRepository;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.jmx.export.MBeanExporter;
@SpringBootApplication
@EnableConfigurationProperties(HelloWorldProperties.class)
public class SampleRedisExportApplication {
@Autowired