Commit c903ff46 authored by Stephane Nicoll's avatar Stephane Nicoll

Polish samples

parent a19a2806
...@@ -27,6 +27,13 @@ ...@@ -27,6 +27,13 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-remote-shell</artifactId> <artifactId>spring-boot-starter-remote-shell</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
......
...@@ -16,14 +16,16 @@ ...@@ -16,14 +16,16 @@
package sample.actuator.noweb; package sample.actuator.noweb;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@Component @Component
public class HelloWorldService { public class HelloWorldService {
@Autowired private final ServiceProperties configuration;
private ServiceProperties configuration;
public HelloWorldService(ServiceProperties configuration) {
this.configuration = configuration;
}
public String getHelloMessage() { public String getHelloMessage() {
return "Hello " + this.configuration.getName(); return "Hello " + this.configuration.getName();
......
...@@ -18,8 +18,10 @@ package sample.actuator.noweb; ...@@ -18,8 +18,10 @@ package sample.actuator.noweb;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@SpringBootApplication @SpringBootApplication
@EnableConfigurationProperties(ServiceProperties.class)
public class SampleActuatorNoWebApplication { public class SampleActuatorNoWebApplication {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
......
...@@ -17,12 +17,13 @@ ...@@ -17,12 +17,13 @@
package sample.actuator.noweb; package sample.actuator.noweb;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@ConfigurationProperties(prefix = "service", ignoreUnknownFields = false) @ConfigurationProperties(prefix = "service", ignoreUnknownFields = false)
@Component
public class ServiceProperties { public class ServiceProperties {
/**
* Name of the service.
*/
private String name = "World"; private String name = "World";
public String getName() { public String getName() {
......
health.diskspace.enabled: false health.diskspace.enabled=false
\ No newline at end of file \ No newline at end of file
...@@ -45,14 +45,16 @@ dependencies { ...@@ -45,14 +45,16 @@ dependencies {
compile("org.springframework.boot:spring-boot-starter-jdbc") compile("org.springframework.boot:spring-boot-starter-jdbc")
compile("org.springframework.boot:spring-boot-starter-security") compile("org.springframework.boot:spring-boot-starter-security")
compile("org.springframework.boot:spring-boot-starter-web") compile("org.springframework.boot:spring-boot-starter-web")
compile("com.h2database:h2") runtime("com.h2database:h2")
compileOnly('org.springframework.boot:spring-boot-configuration-processor')
testCompile("org.springframework.boot:spring-boot-starter-test") testCompile("org.springframework.boot:spring-boot-starter-test")
insecure configurations.runtime insecure configurations.runtime
} }
// Slightly odd requirement (package a jar file as an insecure app, exlcuding Spring Security) // Slightly odd requirement (package a jar file as an insecure app, excluding Spring Security)
// just to demonstrate the "customConfiguration" feature of the Boot gradle plugin. // just to demonstrate the "customConfiguration" feature of the Boot gradle plugin.
springBoot { springBoot {
customConfiguration = "insecure" customConfiguration = "insecure"
......
...@@ -39,10 +39,19 @@ ...@@ -39,10 +39,19 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-remote-shell</artifactId> <artifactId>spring-boot-starter-remote-shell</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.h2database</groupId> <groupId>com.h2database</groupId>
<artifactId>h2</artifactId> <artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
......
...@@ -16,14 +16,16 @@ ...@@ -16,14 +16,16 @@
package sample.actuator; package sample.actuator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@Component @Component
public class HelloWorldService { public class HelloWorldService {
@Autowired private final ServiceProperties configuration;
private ServiceProperties configuration;
public HelloWorldService(ServiceProperties configuration) {
this.configuration = configuration;
}
public String getHelloMessage() { public String getHelloMessage() {
return "Hello " + this.configuration.getName(); return "Hello " + this.configuration.getName();
......
...@@ -20,17 +20,25 @@ import org.springframework.boot.SpringApplication; ...@@ -20,17 +20,25 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.health.Health; import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator; import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
@SpringBootApplication @SpringBootApplication
public class SampleActuatorApplication implements HealthIndicator { @EnableConfigurationProperties(ServiceProperties.class)
public class SampleActuatorApplication {
public static void main(String[] args) throws Exception {
SpringApplication.run(SampleActuatorApplication.class, args);
}
@Bean
public HealthIndicator helloHealthIndicator() {
return new HealthIndicator() {
@Override @Override
public Health health() { public Health health() {
return Health.up().withDetail("hello", "world").build(); return Health.up().withDetail("hello", "world").build();
} }
};
public static void main(String[] args) throws Exception {
SpringApplication.run(SampleActuatorApplication.class, args);
} }
} }
...@@ -23,7 +23,6 @@ import java.util.Map; ...@@ -23,7 +23,6 @@ import java.util.Map;
import org.hibernate.validator.constraints.NotBlank; import org.hibernate.validator.constraints.NotBlank;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Description; import org.springframework.context.annotation.Description;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
...@@ -36,8 +35,11 @@ import org.springframework.web.bind.annotation.ResponseBody; ...@@ -36,8 +35,11 @@ import org.springframework.web.bind.annotation.ResponseBody;
@Description("A controller for handling requests for hello messages") @Description("A controller for handling requests for hello messages")
public class SampleController { public class SampleController {
@Autowired private final HelloWorldService helloWorldService;
private HelloWorldService helloWorldService;
public SampleController(HelloWorldService helloWorldService) {
this.helloWorldService = helloWorldService;
}
@GetMapping("/") @GetMapping("/")
@ResponseBody @ResponseBody
......
...@@ -17,12 +17,13 @@ ...@@ -17,12 +17,13 @@
package sample.actuator; package sample.actuator;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@ConfigurationProperties(prefix = "service", ignoreUnknownFields = false) @ConfigurationProperties(prefix = "service", ignoreUnknownFields = false)
@Component
public class ServiceProperties { public class ServiceProperties {
/**
* Name of the service.
*/
private String name = "World"; private String name = "World";
public String getName() { public String getName() {
......
...@@ -16,24 +16,26 @@ ...@@ -16,24 +16,26 @@
package sample.flyway; package sample.flyway;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner; import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
@SpringBootApplication @SpringBootApplication
public class SampleFlywayApplication implements CommandLineRunner { public class SampleFlywayApplication {
@Autowired public static void main(String[] args) throws Exception {
private PersonRepository repository; SpringApplication.run(SampleFlywayApplication.class, args);
}
@Bean
public CommandLineRunner runner(final PersonRepository repository) {
return new CommandLineRunner() {
@Override @Override
public void run(String... args) throws Exception { public void run(String... args) throws Exception {
System.err.println(this.repository.findAll()); System.err.println(repository.findAll());
} }
};
public static void main(String[] args) throws Exception {
SpringApplication.run(SampleFlywayApplication.class, args);
} }
} }
...@@ -16,19 +16,16 @@ ...@@ -16,19 +16,16 @@
package sample.hypermedia.jpa; package sample.hypermedia.jpa;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
...@@ -37,19 +34,12 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. ...@@ -37,19 +34,12 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest @SpringBootTest
@DirtiesContext @AutoConfigureMockMvc
public class SampleHypermediaJpaApplicationIntegrationTests { public class SampleHypermediaJpaApplicationIntegrationTests {
@Autowired @Autowired
private WebApplicationContext context;
private MockMvc mockMvc; private MockMvc mockMvc;
@Before
public void setUp() {
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context).build();
}
@Test @Test
public void links() throws Exception { public void links() throws Exception {
this.mockMvc.perform(get("/").accept(MediaType.APPLICATION_JSON)) this.mockMvc.perform(get("/").accept(MediaType.APPLICATION_JSON))
......
...@@ -27,6 +27,13 @@ ...@@ -27,6 +27,13 @@
<groupId>org.springframework.integration</groupId> <groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-file</artifactId> <artifactId>spring-integration-file</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
......
logging.level.org.springframework.integration.file: DEBUG logging.level.org.springframework.integration.file=DEBUG
service.greeting: Hello service.greeting=Hello
...@@ -31,6 +31,13 @@ ...@@ -31,6 +31,13 @@
<groupId>io.dropwizard.metrics</groupId> <groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-core</artifactId> <artifactId>metrics-core</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
......
...@@ -17,12 +17,13 @@ ...@@ -17,12 +17,13 @@
package sample.metrics.dropwizard; package sample.metrics.dropwizard;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Component
@ConfigurationProperties(prefix = "service", ignoreUnknownFields = false) @ConfigurationProperties(prefix = "service", ignoreUnknownFields = false)
public class HelloWorldService { public class HelloWorldProperties {
/**
* Name of the service.
*/
private String name = "World"; private String name = "World";
public String getName() { public String getName() {
...@@ -33,8 +34,4 @@ public class HelloWorldService { ...@@ -33,8 +34,4 @@ public class HelloWorldService {
this.name = name; this.name = name;
} }
public String getHelloMessage() {
return "Hello " + this.name;
}
} }
...@@ -19,9 +19,6 @@ package sample.metrics.dropwizard; ...@@ -19,9 +19,6 @@ package sample.metrics.dropwizard;
import java.util.Collections; import java.util.Collections;
import java.util.Map; 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.boot.actuate.metrics.GaugeService;
import org.springframework.context.annotation.Description; import org.springframework.context.annotation.Description;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
...@@ -32,32 +29,21 @@ import org.springframework.web.bind.annotation.ResponseBody; ...@@ -32,32 +29,21 @@ import org.springframework.web.bind.annotation.ResponseBody;
@Description("A controller for handling requests for hello messages") @Description("A controller for handling requests for hello messages")
public class SampleController { public class SampleController {
@Autowired private final HelloWorldProperties helloWorldProperties;
private HelloWorldService helloWorldService;
private final GaugeService gauges;
@Autowired public SampleController(HelloWorldProperties helloWorldProperties, GaugeService gauges) {
private GaugeService gauges; this.helloWorldProperties = helloWorldProperties;
this.gauges = gauges;
}
@GetMapping("/") @GetMapping("/")
@ResponseBody @ResponseBody
public Map<String, String> hello() { public Map<String, String> hello() {
this.gauges.submit("timer.test.value", Math.random() * 1000 + 1000); this.gauges.submit("timer.test.value", Math.random() * 1000 + 1000);
return Collections.singletonMap("message", return Collections.singletonMap("message", "Hello " +
this.helloWorldService.getHelloMessage()); this.helloWorldProperties.getName());
}
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;
}
} }
} }
...@@ -18,8 +18,10 @@ package sample.metrics.dropwizard; ...@@ -18,8 +18,10 @@ package sample.metrics.dropwizard;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@SpringBootApplication @SpringBootApplication
@EnableConfigurationProperties(HelloWorldProperties.class)
public class SampleDropwizardMetricsApplication { public class SampleDropwizardMetricsApplication {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
......
...@@ -27,6 +27,13 @@ ...@@ -27,6 +27,13 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
......
...@@ -17,11 +17,9 @@ ...@@ -17,11 +17,9 @@
package sample.metrics.opentsdb; package sample.metrics.opentsdb;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Component
@ConfigurationProperties(prefix = "service", ignoreUnknownFields = false) @ConfigurationProperties(prefix = "service", ignoreUnknownFields = false)
public class HelloWorldService { public class HelloWorldProperties {
private String name = "World"; private String name = "World";
...@@ -33,8 +31,4 @@ public class HelloWorldService { ...@@ -33,8 +31,4 @@ public class HelloWorldService {
this.name = name; this.name = name;
} }
public String getHelloMessage() {
return "Hello " + this.name;
}
} }
...@@ -21,7 +21,6 @@ import java.util.Map; ...@@ -21,7 +21,6 @@ import java.util.Map;
import org.hibernate.validator.constraints.NotBlank; import org.hibernate.validator.constraints.NotBlank;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Description; import org.springframework.context.annotation.Description;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
...@@ -31,14 +30,17 @@ import org.springframework.web.bind.annotation.ResponseBody; ...@@ -31,14 +30,17 @@ import org.springframework.web.bind.annotation.ResponseBody;
@Description("A controller for handling requests for hello messages") @Description("A controller for handling requests for hello messages")
public class SampleController { public class SampleController {
@Autowired private final HelloWorldProperties helloWorldProperties;
private HelloWorldService helloWorldService;
public SampleController(HelloWorldProperties helloWorldProperties) {
this.helloWorldProperties = helloWorldProperties;
}
@GetMapping("/") @GetMapping("/")
@ResponseBody @ResponseBody
public Map<String, String> hello() { public Map<String, String> hello() {
return Collections.singletonMap("message", return Collections.singletonMap("message", "Hello " +
this.helloWorldService.getHelloMessage()); this.helloWorldProperties.getName());
} }
protected static class Message { protected static class Message {
......
...@@ -20,13 +20,14 @@ import org.springframework.boot.SpringApplication; ...@@ -20,13 +20,14 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.ExportMetricWriter; import org.springframework.boot.actuate.autoconfigure.ExportMetricWriter;
import org.springframework.boot.actuate.metrics.opentsdb.DefaultOpenTsdbNamingStrategy; import org.springframework.boot.actuate.metrics.opentsdb.DefaultOpenTsdbNamingStrategy;
import org.springframework.boot.actuate.metrics.opentsdb.OpenTsdbGaugeWriter; import org.springframework.boot.actuate.metrics.opentsdb.OpenTsdbGaugeWriter;
import org.springframework.boot.actuate.metrics.opentsdb.OpenTsdbNamingStrategy;
import org.springframework.boot.actuate.metrics.writer.GaugeWriter; import org.springframework.boot.actuate.metrics.writer.GaugeWriter;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
@SpringBootApplication @SpringBootApplication
@EnableConfigurationProperties(HelloWorldProperties.class)
public class SampleOpenTsdbExportApplication { public class SampleOpenTsdbExportApplication {
@Bean @Bean
...@@ -40,7 +41,7 @@ public class SampleOpenTsdbExportApplication { ...@@ -40,7 +41,7 @@ public class SampleOpenTsdbExportApplication {
@Bean @Bean
@ConfigurationProperties("metrics.names") @ConfigurationProperties("metrics.names")
public OpenTsdbNamingStrategy namingStrategy() { public DefaultOpenTsdbNamingStrategy namingStrategy() {
return new DefaultOpenTsdbNamingStrategy(); return new DefaultOpenTsdbNamingStrategy();
} }
......
...@@ -31,6 +31,13 @@ ...@@ -31,6 +31,13 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId> <artifactId>spring-boot-starter-data-redis</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
......
...@@ -17,11 +17,9 @@ ...@@ -17,11 +17,9 @@
package sample.metrics.redis; package sample.metrics.redis;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Component
@ConfigurationProperties(prefix = "service", ignoreUnknownFields = false) @ConfigurationProperties(prefix = "service", ignoreUnknownFields = false)
public class HelloWorldService { public class HelloWorldProperties {
private String name = "World"; private String name = "World";
...@@ -33,8 +31,4 @@ public class HelloWorldService { ...@@ -33,8 +31,4 @@ public class HelloWorldService {
this.name = name; this.name = name;
} }
public String getHelloMessage() {
return "Hello " + this.name;
}
} }
...@@ -31,14 +31,18 @@ import org.springframework.web.bind.annotation.ResponseBody; ...@@ -31,14 +31,18 @@ import org.springframework.web.bind.annotation.ResponseBody;
@Description("A controller for handling requests for hello messages") @Description("A controller for handling requests for hello messages")
public class SampleController { public class SampleController {
private final HelloWorldProperties helloWorldProperties;
@Autowired @Autowired
private HelloWorldService helloWorldService; public SampleController(HelloWorldProperties helloWorldProperties) {
this.helloWorldProperties = helloWorldProperties;
}
@GetMapping("/") @GetMapping("/")
@ResponseBody @ResponseBody
public Map<String, String> hello() { public Map<String, String> hello() {
return Collections.singletonMap("message", return Collections.singletonMap("message", "Hello " +
this.helloWorldService.getHelloMessage()); this.helloWorldProperties.getName());
} }
protected static class Message { protected static class Message {
......
...@@ -24,11 +24,13 @@ import org.springframework.boot.actuate.metrics.export.MetricExportProperties; ...@@ -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.jmx.JmxMetricWriter;
import org.springframework.boot.actuate.metrics.repository.redis.RedisMetricRepository; import org.springframework.boot.actuate.metrics.repository.redis.RedisMetricRepository;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.jmx.export.MBeanExporter; import org.springframework.jmx.export.MBeanExporter;
@SpringBootApplication @SpringBootApplication
@EnableConfigurationProperties(HelloWorldProperties.class)
public class SampleRedisExportApplication { public class SampleRedisExportApplication {
@Autowired @Autowired
......
...@@ -16,14 +16,16 @@ ...@@ -16,14 +16,16 @@
package sample.parent; package sample.parent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@Component @Component
public class HelloWorldService { public class HelloWorldService {
@Autowired private final ServiceProperties configuration;
private ServiceProperties configuration;
public HelloWorldService(ServiceProperties configuration) {
this.configuration = configuration;
}
public String getHelloMessage(String name) { public String getHelloMessage(String name) {
return this.configuration.getGreeting() + " " + name; return this.configuration.getGreeting() + " " + name;
......
...@@ -27,8 +27,12 @@ import org.springframework.util.StreamUtils; ...@@ -27,8 +27,12 @@ import org.springframework.util.StreamUtils;
@MessageEndpoint @MessageEndpoint
public class SampleEndpoint { public class SampleEndpoint {
private final HelloWorldService helloWorldService;
@Autowired @Autowired
private HelloWorldService helloWorldService; public SampleEndpoint(HelloWorldService helloWorldService) {
this.helloWorldService = helloWorldService;
}
@ServiceActivator @ServiceActivator
public String hello(File input) throws Exception { public String hello(File input) throws Exception {
......
service.greeting: Hello service.greeting=Hello
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment