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 f9ef72f3bdf..0eb36620285 100644 --- a/spring-boot-samples/spring-boot-sample-actuator-noweb/pom.xml +++ b/spring-boot-samples/spring-boot-sample-actuator-noweb/pom.xml @@ -23,6 +23,13 @@ org.springframework.boot spring-boot-starter-actuator + + + 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 37e8207764f..3a3930054c6 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 73b57036ac1..9e4e8b55896 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/pom.xml +++ b/spring-boot-samples/spring-boot-sample-actuator/pom.xml @@ -38,7 +38,15 @@ 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-cache/src/main/resources/application.properties b/spring-boot-samples/spring-boot-sample-cache/src/main/resources/application.properties index fe24f45857b..2d2395bfe26 100644 --- a/spring-boot-samples/spring-boot-sample-cache/src/main/resources/application.properties +++ b/spring-boot-samples/spring-boot-sample-cache/src/main/resources/application.properties @@ -1,3 +1,5 @@ +management.security.enabled=false + # # Infinispan configuration file location. # diff --git a/spring-boot-samples/spring-boot-sample-data-couchbase/pom.xml b/spring-boot-samples/spring-boot-sample-data-couchbase/pom.xml index 2da17636266..8044cab0190 100644 --- a/spring-boot-samples/spring-boot-sample-data-couchbase/pom.xml +++ b/spring-boot-samples/spring-boot-sample-data-couchbase/pom.xml @@ -18,23 +18,12 @@ ${basedir}/../.. - - org.springframework.boot - spring-boot-starter - org.springframework.boot spring-boot-starter-data-couchbase - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-actuator - - + + org.springframework.boot spring-boot-starter-test test 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-flyway/src/main/resources/application.properties b/spring-boot-samples/spring-boot-sample-flyway/src/main/resources/application.properties index d18bea2e53b..4c1570d1bee 100644 --- a/spring-boot-samples/spring-boot-sample-flyway/src/main/resources/application.properties +++ b/spring-boot-samples/spring-boot-sample-flyway/src/main/resources/application.properties @@ -1,3 +1,5 @@ +management.security.enabled=false + spring.jpa.hibernate.ddl-auto=validate spring.h2.console.enabled=true \ No newline at end of file diff --git a/spring-boot-samples/spring-boot-sample-hypermedia-gson/src/main/resources/application.properties b/spring-boot-samples/spring-boot-sample-hypermedia-gson/src/main/resources/application.properties index 0ed692da147..c869a4aa589 100644 --- a/spring-boot-samples/spring-boot-sample-hypermedia-gson/src/main/resources/application.properties +++ b/spring-boot-samples/spring-boot-sample-hypermedia-gson/src/main/resources/application.properties @@ -1,2 +1,4 @@ # management.context-path=/admin -spring.http.converters.preferred-json-mapper: gson \ No newline at end of file +management.security.enabled=false + +spring.http.converters.preferred-json-mapper=gson \ No newline at end of file diff --git a/spring-boot-samples/spring-boot-sample-hypermedia-gson/src/test/java/sample/hypermedia/gson/SampleHypermediaGsonApplicationTests.java b/spring-boot-samples/spring-boot-sample-hypermedia-gson/src/test/java/sample/hypermedia/gson/SampleHypermediaGsonApplicationTests.java index 515d8886925..ef4702e13b9 100644 --- a/spring-boot-samples/spring-boot-sample-hypermedia-gson/src/test/java/sample/hypermedia/gson/SampleHypermediaGsonApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-hypermedia-gson/src/test/java/sample/hypermedia/gson/SampleHypermediaGsonApplicationTests.java @@ -35,8 +35,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. @RunWith(SpringRunner.class) @SpringBootTest -@TestPropertySource(properties = { "endpoints.hypermedia.enabled: true", - "management.security.enabled: false" }) +@TestPropertySource(properties = "endpoints.hypermedia.enabled: true") public class SampleHypermediaGsonApplicationTests { @Autowired 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-hypermedia-jpa/src/test/java/sample/hypermedia/jpa/SampleHypermediaJpaApplicationTests.java b/spring-boot-samples/spring-boot-sample-hypermedia-jpa/src/test/java/sample/hypermedia/jpa/SampleHypermediaJpaApplicationTests.java deleted file mode 100644 index cf414c85198..00000000000 --- a/spring-boot-samples/spring-boot-sample-hypermedia-jpa/src/test/java/sample/hypermedia/jpa/SampleHypermediaJpaApplicationTests.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2012-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.hypermedia.jpa; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.context.web.WebAppConfiguration; - -@RunWith(SpringRunner.class) -@SpringBootTest -@WebAppConfiguration -public class SampleHypermediaJpaApplicationTests { - - @Test - public void contextLoads() { - } - -} diff --git a/spring-boot-samples/spring-boot-sample-hypermedia-ui/src/main/resources/application.properties b/spring-boot-samples/spring-boot-sample-hypermedia-ui/src/main/resources/application.properties index 8ccf953870d..6f334e794ae 100644 --- a/spring-boot-samples/spring-boot-sample-hypermedia-ui/src/main/resources/application.properties +++ b/spring-boot-samples/spring-boot-sample-hypermedia-ui/src/main/resources/application.properties @@ -1 +1,3 @@ +management.security.enabled=false + management.context-path=/admin \ No newline at end of file diff --git a/spring-boot-samples/spring-boot-sample-hypermedia/src/main/resources/application.properties b/spring-boot-samples/spring-boot-sample-hypermedia/src/main/resources/application.properties index a9198b28f12..0bb2948d11e 100644 --- a/spring-boot-samples/spring-boot-sample-hypermedia/src/main/resources/application.properties +++ b/spring-boot-samples/spring-boot-sample-hypermedia/src/main/resources/application.properties @@ -1,2 +1,4 @@ # management.context-path=/admin +management.security.enabled=false + endpoints.docs.curies.enabled=true \ No newline at end of file diff --git a/spring-boot-samples/spring-boot-sample-integration/pom.xml b/spring-boot-samples/spring-boot-sample-integration/pom.xml index 2aa28173901..1b653346759 100644 --- a/spring-boot-samples/spring-boot-sample-integration/pom.xml +++ b/spring-boot-samples/spring-boot-sample-integration/pom.xml @@ -23,14 +23,17 @@ org.springframework.boot spring-boot-starter-integration - - org.springframework.boot - spring-boot-starter-actuator - 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-jersey/pom.xml b/spring-boot-samples/spring-boot-sample-jersey/pom.xml index c7986b33700..33e3c89d379 100644 --- a/spring-boot-samples/spring-boot-sample-jersey/pom.xml +++ b/spring-boot-samples/spring-boot-sample-jersey/pom.xml @@ -29,10 +29,7 @@ spring-boot-starter-tomcat provided - - org.springframework.boot - spring-boot-starter-actuator - + org.springframework.boot spring-boot-starter-test diff --git a/spring-boot-samples/spring-boot-sample-liquibase/src/main/resources/application.properties b/spring-boot-samples/spring-boot-sample-liquibase/src/main/resources/application.properties index 288b7e85ad7..42f0f812295 100644 --- a/spring-boot-samples/spring-boot-sample-liquibase/src/main/resources/application.properties +++ b/spring-boot-samples/spring-boot-sample-liquibase/src/main/resources/application.properties @@ -1,3 +1,5 @@ +management.security.enabled=false + spring.jpa.hibernate.ddl-auto=none spring.h2.console.enabled=true 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 dca91c7fe45..36611616ea6 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/HelloWorldService.java b/spring-boot-samples/spring-boot-sample-metrics-dropwizard/src/main/java/sample/metrics/dropwizard/HelloWorldProperties.java similarity index 85% rename from spring-boot-samples/spring-boot-sample-metrics-dropwizard/src/main/java/sample/metrics/dropwizard/HelloWorldService.java rename to 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/HelloWorldService.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-dropwizard/src/main/resources/application.properties b/spring-boot-samples/spring-boot-sample-metrics-dropwizard/src/main/resources/application.properties index 41071924755..119a68aa433 100644 --- a/spring-boot-samples/spring-boot-sample-metrics-dropwizard/src/main/resources/application.properties +++ b/spring-boot-samples/spring-boot-sample-metrics-dropwizard/src/main/resources/application.properties @@ -1 +1,3 @@ -service.name: Phil +management.security.enabled=false + +service.name=Phil 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 d4b27c70047..7b97c67758a 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/HelloWorldService.java b/spring-boot-samples/spring-boot-sample-metrics-opentsdb/src/main/java/sample/metrics/opentsdb/HelloWorldProperties.java similarity index 85% rename from spring-boot-samples/spring-boot-sample-metrics-opentsdb/src/main/java/sample/metrics/opentsdb/HelloWorldService.java rename to 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/HelloWorldService.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-opentsdb/src/main/resources/application.properties b/spring-boot-samples/spring-boot-sample-metrics-opentsdb/src/main/resources/application.properties index 22fc8604904..e092b8e642f 100644 --- a/spring-boot-samples/spring-boot-sample-metrics-opentsdb/src/main/resources/application.properties +++ b/spring-boot-samples/spring-boot-sample-metrics-opentsdb/src/main/resources/application.properties @@ -1,2 +1,4 @@ -service.name: Phil -metrics.names.tags.process: ${spring.application.name:application}:${random.value:0000} \ No newline at end of file +management.security.enabled=false + +service.name=Phil +metrics.names.tags.process=${spring.application.name:application}:${random.value:0000} \ No newline at end of file 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 abf39ff9a26..72090430870 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/HelloWorldService.java b/spring-boot-samples/spring-boot-sample-metrics-redis/src/main/java/sample/metrics/redis/HelloWorldProperties.java similarity index 85% rename from spring-boot-samples/spring-boot-sample-metrics-redis/src/main/java/sample/metrics/redis/HelloWorldService.java rename to 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/HelloWorldService.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-metrics-redis/src/main/resources/application.properties b/spring-boot-samples/spring-boot-sample-metrics-redis/src/main/resources/application.properties index 78f2c31ab4f..0cf56ec17f8 100644 --- a/spring-boot-samples/spring-boot-sample-metrics-redis/src/main/resources/application.properties +++ b/spring-boot-samples/spring-boot-sample-metrics-redis/src/main/resources/application.properties @@ -1,7 +1,9 @@ -service.name: Phil -spring.metrics.export.redis.prefix: metrics.sample.${spring.metrics.export.aggregate.prefix} -spring.metrics.export.redis.key: keys.metrics.sample -spring.metrics.export.aggregate.prefix: ${random.value:0000}.${spring.application.name:application} -spring.metrics.export.aggregate.key-pattern: d -spring.jmx.default-domain: org.springframework.boot +management.security.enabled=false + +service.name=Phil +spring.metrics.export.redis.prefix=metrics.sample.${spring.metrics.export.aggregate.prefix} +spring.metrics.export.redis.key=keys.metrics.sample +spring.metrics.export.aggregate.prefix=${random.value:0000}.${spring.application.name:application} +spring.metrics.export.aggregate.key-pattern=d +spring.jmx.default-domain=org.springframework.boot spring.data.redis.repositories.enabled=false \ No newline at end of file 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 diff --git a/spring-boot-samples/spring-boot-sample-web-static/pom.xml b/spring-boot-samples/spring-boot-sample-web-static/pom.xml index cd1a50a9922..2a77774b09d 100644 --- a/spring-boot-samples/spring-boot-sample-web-static/pom.xml +++ b/spring-boot-samples/spring-boot-sample-web-static/pom.xml @@ -24,10 +24,6 @@ org.springframework.boot spring-boot-starter-web - - org.springframework.boot - spring-boot-starter-actuator - org.springframework.boot spring-boot-starter-tomcat diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/pom.xml b/spring-boot-samples/spring-boot-sample-websocket-jetty/pom.xml index 2d6dfc89e8c..261bacc3021 100755 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/pom.xml +++ b/spring-boot-samples/spring-boot-sample-websocket-jetty/pom.xml @@ -33,10 +33,6 @@ org.springframework.boot spring-boot-starter-jetty - - org.springframework.boot - spring-boot-starter-actuator - org.springframework.boot spring-boot-starter-test diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty93/pom.xml b/spring-boot-samples/spring-boot-sample-websocket-jetty93/pom.xml index 4dcc1aaa655..08a072f18b7 100755 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty93/pom.xml +++ b/spring-boot-samples/spring-boot-sample-websocket-jetty93/pom.xml @@ -35,10 +35,6 @@ org.springframework.boot spring-boot-starter-jetty - - org.springframework.boot - spring-boot-starter-actuator - org.springframework.boot spring-boot-starter-test diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/pom.xml b/spring-boot-samples/spring-boot-sample-websocket-tomcat/pom.xml index 405340acfe2..a65f74ce0ad 100755 --- a/spring-boot-samples/spring-boot-sample-websocket-tomcat/pom.xml +++ b/spring-boot-samples/spring-boot-sample-websocket-tomcat/pom.xml @@ -23,10 +23,6 @@ org.springframework.boot spring-boot-starter-websocket - - org.springframework.boot - spring-boot-starter-actuator - org.springframework.boot spring-boot-starter-test diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/pom.xml b/spring-boot-samples/spring-boot-sample-websocket-undertow/pom.xml index 929e65b5c1a..7a1af3dcf8f 100755 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/pom.xml +++ b/spring-boot-samples/spring-boot-sample-websocket-undertow/pom.xml @@ -33,10 +33,6 @@ org.springframework.boot spring-boot-starter-undertow - - org.springframework.boot - spring-boot-starter-actuator - org.springframework.boot spring-boot-starter-test