diff --git a/spring-boot-samples/spring-boot-sample-actuator-noweb/pom.xml b/spring-boot-samples/spring-boot-sample-actuator-noweb/pom.xml
index eae884e4de9..8920257b715 100644
--- a/spring-boot-samples/spring-boot-sample-actuator-noweb/pom.xml
+++ b/spring-boot-samples/spring-boot-sample-actuator-noweb/pom.xml
@@ -27,6 +27,13 @@
org.springframework.boot
spring-boot-starter-remote-shell
+
+
+ org.springframework.boot
+ spring-boot-configuration-processor
+ true
+
+
org.springframework.boot
spring-boot-starter-test
diff --git a/spring-boot-samples/spring-boot-sample-actuator-noweb/src/main/java/sample/actuator/noweb/HelloWorldService.java b/spring-boot-samples/spring-boot-sample-actuator-noweb/src/main/java/sample/actuator/noweb/HelloWorldService.java
index 50fbda8c7ae..0fc0ec648d7 100644
--- a/spring-boot-samples/spring-boot-sample-actuator-noweb/src/main/java/sample/actuator/noweb/HelloWorldService.java
+++ b/spring-boot-samples/spring-boot-sample-actuator-noweb/src/main/java/sample/actuator/noweb/HelloWorldService.java
@@ -16,14 +16,16 @@
package sample.actuator.noweb;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class HelloWorldService {
- @Autowired
- private ServiceProperties configuration;
+ private final ServiceProperties configuration;
+
+ public HelloWorldService(ServiceProperties configuration) {
+ this.configuration = configuration;
+ }
public String getHelloMessage() {
return "Hello " + this.configuration.getName();
diff --git a/spring-boot-samples/spring-boot-sample-actuator-noweb/src/main/java/sample/actuator/noweb/SampleActuatorNoWebApplication.java b/spring-boot-samples/spring-boot-sample-actuator-noweb/src/main/java/sample/actuator/noweb/SampleActuatorNoWebApplication.java
index b2229c6f902..ae22617f29c 100644
--- a/spring-boot-samples/spring-boot-sample-actuator-noweb/src/main/java/sample/actuator/noweb/SampleActuatorNoWebApplication.java
+++ b/spring-boot-samples/spring-boot-sample-actuator-noweb/src/main/java/sample/actuator/noweb/SampleActuatorNoWebApplication.java
@@ -18,8 +18,10 @@ package sample.actuator.noweb;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
@SpringBootApplication
+@EnableConfigurationProperties(ServiceProperties.class)
public class SampleActuatorNoWebApplication {
public static void main(String[] args) throws Exception {
diff --git a/spring-boot-samples/spring-boot-sample-actuator-noweb/src/main/java/sample/actuator/noweb/ServiceProperties.java b/spring-boot-samples/spring-boot-sample-actuator-noweb/src/main/java/sample/actuator/noweb/ServiceProperties.java
index ded4e849586..8a367b2000a 100644
--- a/spring-boot-samples/spring-boot-sample-actuator-noweb/src/main/java/sample/actuator/noweb/ServiceProperties.java
+++ b/spring-boot-samples/spring-boot-sample-actuator-noweb/src/main/java/sample/actuator/noweb/ServiceProperties.java
@@ -17,12 +17,13 @@
package sample.actuator.noweb;
import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.stereotype.Component;
@ConfigurationProperties(prefix = "service", ignoreUnknownFields = false)
-@Component
public class ServiceProperties {
+ /**
+ * Name of the service.
+ */
private String name = "World";
public String getName() {
diff --git a/spring-boot-samples/spring-boot-sample-actuator-ui/src/main/resources/application.properties b/spring-boot-samples/spring-boot-sample-actuator-ui/src/main/resources/application.properties
index 84fea2762ca..4b4a8161137 100644
--- a/spring-boot-samples/spring-boot-sample-actuator-ui/src/main/resources/application.properties
+++ b/spring-boot-samples/spring-boot-sample-actuator-ui/src/main/resources/application.properties
@@ -1 +1 @@
-health.diskspace.enabled: false
\ No newline at end of file
+health.diskspace.enabled=false
\ No newline at end of file
diff --git a/spring-boot-samples/spring-boot-sample-actuator/build.gradle b/spring-boot-samples/spring-boot-sample-actuator/build.gradle
index bccea38ce13..a87b248711b 100644
--- a/spring-boot-samples/spring-boot-sample-actuator/build.gradle
+++ b/spring-boot-samples/spring-boot-sample-actuator/build.gradle
@@ -45,14 +45,16 @@ dependencies {
compile("org.springframework.boot:spring-boot-starter-jdbc")
compile("org.springframework.boot:spring-boot-starter-security")
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")
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.
springBoot {
customConfiguration = "insecure"
diff --git a/spring-boot-samples/spring-boot-sample-actuator/pom.xml b/spring-boot-samples/spring-boot-sample-actuator/pom.xml
index 68852f61ae2..d08ea2710ed 100644
--- a/spring-boot-samples/spring-boot-sample-actuator/pom.xml
+++ b/spring-boot-samples/spring-boot-sample-actuator/pom.xml
@@ -39,10 +39,19 @@
org.springframework.boot
spring-boot-starter-remote-shell
+
com.h2database
h2
+ runtime
+
+
+ org.springframework.boot
+ spring-boot-configuration-processor
+ true
+
+
org.springframework.boot
spring-boot-starter-test
diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/HelloWorldService.java b/spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/HelloWorldService.java
index e383208ce06..1c742c7d07d 100644
--- a/spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/HelloWorldService.java
+++ b/spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/HelloWorldService.java
@@ -16,14 +16,16 @@
package sample.actuator;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class HelloWorldService {
- @Autowired
- private ServiceProperties configuration;
+ private final ServiceProperties configuration;
+
+ public HelloWorldService(ServiceProperties configuration) {
+ this.configuration = configuration;
+ }
public String getHelloMessage() {
return "Hello " + this.configuration.getName();
diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/SampleActuatorApplication.java b/spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/SampleActuatorApplication.java
index 5e50ddb1b46..7ccb57bf7f1 100644
--- a/spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/SampleActuatorApplication.java
+++ b/spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/SampleActuatorApplication.java
@@ -20,17 +20,25 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
@SpringBootApplication
-public class SampleActuatorApplication implements HealthIndicator {
-
- @Override
- public Health health() {
- return Health.up().withDetail("hello", "world").build();
- }
+@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
+ public Health health() {
+ return Health.up().withDetail("hello", "world").build();
+ }
+ };
+ }
+
}
diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/SampleController.java b/spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/SampleController.java
index 24d28a68017..1dcc6054e2a 100644
--- a/spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/SampleController.java
+++ b/spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/SampleController.java
@@ -23,7 +23,6 @@ import java.util.Map;
import org.hibernate.validator.constraints.NotBlank;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Description;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
@@ -36,8 +35,11 @@ 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 HelloWorldService helloWorldService;
+
+ public SampleController(HelloWorldService helloWorldService) {
+ this.helloWorldService = helloWorldService;
+ }
@GetMapping("/")
@ResponseBody
diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/ServiceProperties.java b/spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/ServiceProperties.java
index 44a0f581ebf..1c73c7fe59d 100644
--- a/spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/ServiceProperties.java
+++ b/spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/ServiceProperties.java
@@ -17,12 +17,13 @@
package sample.actuator;
import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.stereotype.Component;
@ConfigurationProperties(prefix = "service", ignoreUnknownFields = false)
-@Component
public class ServiceProperties {
+ /**
+ * Name of the service.
+ */
private String name = "World";
public String getName() {
diff --git a/spring-boot-samples/spring-boot-sample-flyway/src/main/java/sample/flyway/SampleFlywayApplication.java b/spring-boot-samples/spring-boot-sample-flyway/src/main/java/sample/flyway/SampleFlywayApplication.java
index e2c18127be3..2323bd27704 100644
--- a/spring-boot-samples/spring-boot-sample-flyway/src/main/java/sample/flyway/SampleFlywayApplication.java
+++ b/spring-boot-samples/spring-boot-sample-flyway/src/main/java/sample/flyway/SampleFlywayApplication.java
@@ -16,24 +16,26 @@
package sample.flyway;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.Bean;
@SpringBootApplication
-public class SampleFlywayApplication implements CommandLineRunner {
-
- @Autowired
- private PersonRepository repository;
-
- @Override
- public void run(String... args) throws Exception {
- System.err.println(this.repository.findAll());
- }
+public class SampleFlywayApplication {
public static void main(String[] args) throws Exception {
SpringApplication.run(SampleFlywayApplication.class, args);
}
+ @Bean
+ public CommandLineRunner runner(final PersonRepository repository) {
+ return new CommandLineRunner() {
+ @Override
+ public void run(String... args) throws Exception {
+ System.err.println(repository.findAll());
+ }
+ };
+ }
+
}
diff --git a/spring-boot-samples/spring-boot-sample-hypermedia-jpa/src/test/java/sample/hypermedia/jpa/SampleHypermediaJpaApplicationIntegrationTests.java b/spring-boot-samples/spring-boot-sample-hypermedia-jpa/src/test/java/sample/hypermedia/jpa/SampleHypermediaJpaApplicationIntegrationTests.java
index 115afc7d53a..d81b6f7ab43 100644
--- a/spring-boot-samples/spring-boot-sample-hypermedia-jpa/src/test/java/sample/hypermedia/jpa/SampleHypermediaJpaApplicationIntegrationTests.java
+++ b/spring-boot-samples/spring-boot-sample-hypermedia-jpa/src/test/java/sample/hypermedia/jpa/SampleHypermediaJpaApplicationIntegrationTests.java
@@ -16,19 +16,16 @@
package sample.hypermedia.jpa;
-import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
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.http.MediaType;
-import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
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.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
@@ -37,19 +34,12 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@RunWith(SpringRunner.class)
@SpringBootTest
-@DirtiesContext
+@AutoConfigureMockMvc
public class SampleHypermediaJpaApplicationIntegrationTests {
@Autowired
- private WebApplicationContext context;
-
private MockMvc mockMvc;
- @Before
- public void setUp() {
- this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context).build();
- }
-
@Test
public void links() throws Exception {
this.mockMvc.perform(get("/").accept(MediaType.APPLICATION_JSON))
diff --git a/spring-boot-samples/spring-boot-sample-integration/pom.xml b/spring-boot-samples/spring-boot-sample-integration/pom.xml
index e27be19beb6..28a972c873f 100644
--- a/spring-boot-samples/spring-boot-sample-integration/pom.xml
+++ b/spring-boot-samples/spring-boot-sample-integration/pom.xml
@@ -27,6 +27,13 @@
org.springframework.integration
spring-integration-file
+
+
+ org.springframework.boot
+ spring-boot-configuration-processor
+ true
+
+
org.springframework.boot
spring-boot-starter-test
diff --git a/spring-boot-samples/spring-boot-sample-integration/src/main/resources/application.properties b/spring-boot-samples/spring-boot-sample-integration/src/main/resources/application.properties
index 1a341165477..cac3e48600f 100644
--- a/spring-boot-samples/spring-boot-sample-integration/src/main/resources/application.properties
+++ b/spring-boot-samples/spring-boot-sample-integration/src/main/resources/application.properties
@@ -1,2 +1,2 @@
-logging.level.org.springframework.integration.file: DEBUG
-service.greeting: Hello
+logging.level.org.springframework.integration.file=DEBUG
+service.greeting=Hello
diff --git a/spring-boot-samples/spring-boot-sample-metrics-dropwizard/pom.xml b/spring-boot-samples/spring-boot-sample-metrics-dropwizard/pom.xml
index 07d022a2c14..f729b2ed84f 100644
--- a/spring-boot-samples/spring-boot-sample-metrics-dropwizard/pom.xml
+++ b/spring-boot-samples/spring-boot-sample-metrics-dropwizard/pom.xml
@@ -31,6 +31,13 @@
io.dropwizard.metrics
metrics-core
+
+
+ org.springframework.boot
+ spring-boot-configuration-processor
+ true
+
+
org.springframework.boot
spring-boot-starter-test
diff --git a/spring-boot-samples/spring-boot-sample-metrics-dropwizard/src/main/java/sample/metrics/dropwizard/HelloWorldProperties.java b/spring-boot-samples/spring-boot-sample-metrics-dropwizard/src/main/java/sample/metrics/dropwizard/HelloWorldProperties.java
index 6f7dd258c7d..01a68d5f63a 100644
--- a/spring-boot-samples/spring-boot-sample-metrics-dropwizard/src/main/java/sample/metrics/dropwizard/HelloWorldProperties.java
+++ b/spring-boot-samples/spring-boot-sample-metrics-dropwizard/src/main/java/sample/metrics/dropwizard/HelloWorldProperties.java
@@ -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;
- }
-
}
diff --git a/spring-boot-samples/spring-boot-sample-metrics-dropwizard/src/main/java/sample/metrics/dropwizard/SampleController.java b/spring-boot-samples/spring-boot-sample-metrics-dropwizard/src/main/java/sample/metrics/dropwizard/SampleController.java
index 749b794007e..f10b95c3085 100644
--- a/spring-boot-samples/spring-boot-sample-metrics-dropwizard/src/main/java/sample/metrics/dropwizard/SampleController.java
+++ b/spring-boot-samples/spring-boot-sample-metrics-dropwizard/src/main/java/sample/metrics/dropwizard/SampleController.java
@@ -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 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());
}
}
diff --git a/spring-boot-samples/spring-boot-sample-metrics-dropwizard/src/main/java/sample/metrics/dropwizard/SampleDropwizardMetricsApplication.java b/spring-boot-samples/spring-boot-sample-metrics-dropwizard/src/main/java/sample/metrics/dropwizard/SampleDropwizardMetricsApplication.java
index ff902cf54c5..da8f9ba5b9d 100644
--- a/spring-boot-samples/spring-boot-sample-metrics-dropwizard/src/main/java/sample/metrics/dropwizard/SampleDropwizardMetricsApplication.java
+++ b/spring-boot-samples/spring-boot-sample-metrics-dropwizard/src/main/java/sample/metrics/dropwizard/SampleDropwizardMetricsApplication.java
@@ -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 {
diff --git a/spring-boot-samples/spring-boot-sample-metrics-opentsdb/pom.xml b/spring-boot-samples/spring-boot-sample-metrics-opentsdb/pom.xml
index 5bde109b85b..f9ab793f6c8 100644
--- a/spring-boot-samples/spring-boot-sample-metrics-opentsdb/pom.xml
+++ b/spring-boot-samples/spring-boot-sample-metrics-opentsdb/pom.xml
@@ -27,6 +27,13 @@
org.springframework.boot
spring-boot-starter-web
+
+
+ org.springframework.boot
+ spring-boot-configuration-processor
+ true
+
+
org.springframework.boot
spring-boot-starter-test
diff --git a/spring-boot-samples/spring-boot-sample-metrics-opentsdb/src/main/java/sample/metrics/opentsdb/HelloWorldProperties.java b/spring-boot-samples/spring-boot-sample-metrics-opentsdb/src/main/java/sample/metrics/opentsdb/HelloWorldProperties.java
index 69ca04ebb9b..7ac058c2637 100644
--- a/spring-boot-samples/spring-boot-sample-metrics-opentsdb/src/main/java/sample/metrics/opentsdb/HelloWorldProperties.java
+++ b/spring-boot-samples/spring-boot-sample-metrics-opentsdb/src/main/java/sample/metrics/opentsdb/HelloWorldProperties.java
@@ -17,11 +17,9 @@
package sample.metrics.opentsdb;
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;
- }
-
}
diff --git a/spring-boot-samples/spring-boot-sample-metrics-opentsdb/src/main/java/sample/metrics/opentsdb/SampleController.java b/spring-boot-samples/spring-boot-sample-metrics-opentsdb/src/main/java/sample/metrics/opentsdb/SampleController.java
index 5101d122a3a..2fa39f6a96a 100644
--- a/spring-boot-samples/spring-boot-sample-metrics-opentsdb/src/main/java/sample/metrics/opentsdb/SampleController.java
+++ b/spring-boot-samples/spring-boot-sample-metrics-opentsdb/src/main/java/sample/metrics/opentsdb/SampleController.java
@@ -21,7 +21,6 @@ import java.util.Map;
import org.hibernate.validator.constraints.NotBlank;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Description;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@@ -31,14 +30,17 @@ 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;
+
+ public SampleController(HelloWorldProperties helloWorldProperties) {
+ this.helloWorldProperties = helloWorldProperties;
+ }
@GetMapping("/")
@ResponseBody
public Map hello() {
- return Collections.singletonMap("message",
- this.helloWorldService.getHelloMessage());
+ return Collections.singletonMap("message", "Hello " +
+ this.helloWorldProperties.getName());
}
protected static class Message {
diff --git a/spring-boot-samples/spring-boot-sample-metrics-opentsdb/src/main/java/sample/metrics/opentsdb/SampleOpenTsdbExportApplication.java b/spring-boot-samples/spring-boot-sample-metrics-opentsdb/src/main/java/sample/metrics/opentsdb/SampleOpenTsdbExportApplication.java
index a985bf65598..e1174d686e7 100644
--- a/spring-boot-samples/spring-boot-sample-metrics-opentsdb/src/main/java/sample/metrics/opentsdb/SampleOpenTsdbExportApplication.java
+++ b/spring-boot-samples/spring-boot-sample-metrics-opentsdb/src/main/java/sample/metrics/opentsdb/SampleOpenTsdbExportApplication.java
@@ -20,13 +20,14 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.ExportMetricWriter;
import org.springframework.boot.actuate.metrics.opentsdb.DefaultOpenTsdbNamingStrategy;
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.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
+@EnableConfigurationProperties(HelloWorldProperties.class)
public class SampleOpenTsdbExportApplication {
@Bean
@@ -40,7 +41,7 @@ public class SampleOpenTsdbExportApplication {
@Bean
@ConfigurationProperties("metrics.names")
- public OpenTsdbNamingStrategy namingStrategy() {
+ public DefaultOpenTsdbNamingStrategy namingStrategy() {
return new DefaultOpenTsdbNamingStrategy();
}
diff --git a/spring-boot-samples/spring-boot-sample-metrics-redis/pom.xml b/spring-boot-samples/spring-boot-sample-metrics-redis/pom.xml
index f88a0dfdd39..be55aff483b 100644
--- a/spring-boot-samples/spring-boot-sample-metrics-redis/pom.xml
+++ b/spring-boot-samples/spring-boot-sample-metrics-redis/pom.xml
@@ -31,6 +31,13 @@
org.springframework.boot
spring-boot-starter-data-redis
+
+
+ org.springframework.boot
+ spring-boot-configuration-processor
+ true
+
+
org.springframework.boot
spring-boot-starter-test
diff --git a/spring-boot-samples/spring-boot-sample-metrics-redis/src/main/java/sample/metrics/redis/HelloWorldProperties.java b/spring-boot-samples/spring-boot-sample-metrics-redis/src/main/java/sample/metrics/redis/HelloWorldProperties.java
index 9b08174c008..ff9a6e52b58 100644
--- a/spring-boot-samples/spring-boot-sample-metrics-redis/src/main/java/sample/metrics/redis/HelloWorldProperties.java
+++ b/spring-boot-samples/spring-boot-sample-metrics-redis/src/main/java/sample/metrics/redis/HelloWorldProperties.java
@@ -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;
- }
-
}
diff --git a/spring-boot-samples/spring-boot-sample-metrics-redis/src/main/java/sample/metrics/redis/SampleController.java b/spring-boot-samples/spring-boot-sample-metrics-redis/src/main/java/sample/metrics/redis/SampleController.java
index b325a31cba7..2285cde285f 100644
--- a/spring-boot-samples/spring-boot-sample-metrics-redis/src/main/java/sample/metrics/redis/SampleController.java
+++ b/spring-boot-samples/spring-boot-sample-metrics-redis/src/main/java/sample/metrics/redis/SampleController.java
@@ -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 hello() {
- return Collections.singletonMap("message",
- this.helloWorldService.getHelloMessage());
+ return Collections.singletonMap("message", "Hello " +
+ this.helloWorldProperties.getName());
}
protected static class Message {
diff --git a/spring-boot-samples/spring-boot-sample-metrics-redis/src/main/java/sample/metrics/redis/SampleRedisExportApplication.java b/spring-boot-samples/spring-boot-sample-metrics-redis/src/main/java/sample/metrics/redis/SampleRedisExportApplication.java
index 97f7186c840..8ee236972b0 100644
--- a/spring-boot-samples/spring-boot-sample-metrics-redis/src/main/java/sample/metrics/redis/SampleRedisExportApplication.java
+++ b/spring-boot-samples/spring-boot-sample-metrics-redis/src/main/java/sample/metrics/redis/SampleRedisExportApplication.java
@@ -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
diff --git a/spring-boot-samples/spring-boot-sample-parent-context/src/main/java/sample/parent/HelloWorldService.java b/spring-boot-samples/spring-boot-sample-parent-context/src/main/java/sample/parent/HelloWorldService.java
index f318887c452..76c94d18825 100644
--- a/spring-boot-samples/spring-boot-sample-parent-context/src/main/java/sample/parent/HelloWorldService.java
+++ b/spring-boot-samples/spring-boot-sample-parent-context/src/main/java/sample/parent/HelloWorldService.java
@@ -16,14 +16,16 @@
package sample.parent;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class HelloWorldService {
- @Autowired
- private ServiceProperties configuration;
+ private final ServiceProperties configuration;
+
+ public HelloWorldService(ServiceProperties configuration) {
+ this.configuration = configuration;
+ }
public String getHelloMessage(String name) {
return this.configuration.getGreeting() + " " + name;
diff --git a/spring-boot-samples/spring-boot-sample-parent-context/src/main/java/sample/parent/SampleEndpoint.java b/spring-boot-samples/spring-boot-sample-parent-context/src/main/java/sample/parent/SampleEndpoint.java
index d17d8dfbaac..2a346a24da9 100644
--- a/spring-boot-samples/spring-boot-sample-parent-context/src/main/java/sample/parent/SampleEndpoint.java
+++ b/spring-boot-samples/spring-boot-sample-parent-context/src/main/java/sample/parent/SampleEndpoint.java
@@ -27,8 +27,12 @@ import org.springframework.util.StreamUtils;
@MessageEndpoint
public class SampleEndpoint {
+ private final HelloWorldService helloWorldService;
+
@Autowired
- private HelloWorldService helloWorldService;
+ public SampleEndpoint(HelloWorldService helloWorldService) {
+ this.helloWorldService = helloWorldService;
+ }
@ServiceActivator
public String hello(File input) throws Exception {
diff --git a/spring-boot-samples/spring-boot-sample-parent-context/src/main/resources/application.properties b/spring-boot-samples/spring-boot-sample-parent-context/src/main/resources/application.properties
index f1309dd4e46..b04af6c76a1 100644
--- a/spring-boot-samples/spring-boot-sample-parent-context/src/main/resources/application.properties
+++ b/spring-boot-samples/spring-boot-sample-parent-context/src/main/resources/application.properties
@@ -1 +1 @@
-service.greeting: Hello
\ No newline at end of file
+service.greeting=Hello
\ No newline at end of file