Merge branch '1.5.x'

This commit is contained in:
Stephane Nicoll 2016-12-30 18:01:59 +01:00
commit 4604bb7e8a
48 changed files with 180 additions and 193 deletions

View File

@ -23,6 +23,13 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId> <artifactId>spring-boot-starter-actuator</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>

View File

@ -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();

View File

@ -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 {

View File

@ -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() {

View File

@ -1 +1 @@
health.diskspace.enabled: false health.diskspace.enabled=false

View File

@ -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"

View File

@ -38,7 +38,15 @@
<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>

View File

@ -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();

View File

@ -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 {
@Override
public Health health() {
return Health.up().withDetail("hello", "world").build();
}
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
SpringApplication.run(SampleActuatorApplication.class, args); SpringApplication.run(SampleActuatorApplication.class, args);
} }
@Bean
public HealthIndicator helloHealthIndicator() {
return new HealthIndicator() {
@Override
public Health health() {
return Health.up().withDetail("hello", "world").build();
}
};
}
} }

View File

@ -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;
@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

View File

@ -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() {

View File

@ -1,3 +1,5 @@
management.security.enabled=false
# #
# Infinispan configuration file location. # Infinispan configuration file location.
# #

View File

@ -18,23 +18,12 @@
<main.basedir>${basedir}/../..</main.basedir> <main.basedir>${basedir}/../..</main.basedir>
</properties> </properties>
<dependencies> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-couchbase</artifactId> <artifactId>spring-boot-starter-data-couchbase</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId> <dependency>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope> <scope>test</scope>

View File

@ -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
private PersonRepository repository;
@Override
public void run(String... args) throws Exception {
System.err.println(this.repository.findAll());
}
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
SpringApplication.run(SampleFlywayApplication.class, args); 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());
}
};
}
} }

View File

@ -1,3 +1,5 @@
management.security.enabled=false
spring.jpa.hibernate.ddl-auto=validate spring.jpa.hibernate.ddl-auto=validate
spring.h2.console.enabled=true spring.h2.console.enabled=true

View File

@ -1,2 +1,4 @@
# management.context-path=/admin # management.context-path=/admin
spring.http.converters.preferred-json-mapper: gson management.security.enabled=false
spring.http.converters.preferred-json-mapper=gson

View File

@ -35,8 +35,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest @SpringBootTest
@TestPropertySource(properties = { "endpoints.hypermedia.enabled: true", @TestPropertySource(properties = "endpoints.hypermedia.enabled: true")
"management.security.enabled: false" })
public class SampleHypermediaGsonApplicationTests { public class SampleHypermediaGsonApplicationTests {
@Autowired @Autowired

View File

@ -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.
@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))

View File

@ -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() {
}
}

View File

@ -1 +1,3 @@
management.security.enabled=false
management.context-path=/admin management.context-path=/admin

View File

@ -1,2 +1,4 @@
# management.context-path=/admin # management.context-path=/admin
management.security.enabled=false
endpoints.docs.curies.enabled=true endpoints.docs.curies.enabled=true

View File

@ -23,14 +23,17 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-integration</artifactId> <artifactId>spring-boot-starter-integration</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency> <dependency>
<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>

View File

@ -1,2 +1,2 @@
logging.level.org.springframework.integration.file: DEBUG logging.level.org.springframework.integration.file=DEBUG
service.greeting: Hello service.greeting=Hello

View File

@ -29,10 +29,7 @@
<artifactId>spring-boot-starter-tomcat</artifactId> <artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</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>

View File

@ -1,3 +1,5 @@
management.security.enabled=false
spring.jpa.hibernate.ddl-auto=none spring.jpa.hibernate.ddl-auto=none
spring.h2.console.enabled=true spring.h2.console.enabled=true

View File

@ -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>

View File

@ -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 {
this.name = name; this.name = name;
} }
public String getHelloMessage() {
return "Hello " + this.name;
}
} }

View File

@ -19,9 +19,6 @@ package sample.metrics.dropwizard;
import java.util.Collections; import java.util.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;
@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;
@Autowired private final GaugeService gauges;
private GaugeService gauges;
public SampleController(HelloWorldProperties helloWorldProperties, 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;
}
} }
} }

View File

@ -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 {

View File

@ -1 +1,3 @@
service.name: Phil management.security.enabled=false
service.name=Phil

View File

@ -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>

View File

@ -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 {
this.name = name; this.name = name;
} }
public String getHelloMessage() {
return "Hello " + this.name;
}
} }

View File

@ -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;
@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 {

View File

@ -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 {
@Bean @Bean
@ConfigurationProperties("metrics.names") @ConfigurationProperties("metrics.names")
public OpenTsdbNamingStrategy namingStrategy() { public DefaultOpenTsdbNamingStrategy namingStrategy() {
return new DefaultOpenTsdbNamingStrategy(); return new DefaultOpenTsdbNamingStrategy();
} }

View File

@ -1,2 +1,4 @@
service.name: Phil management.security.enabled=false
metrics.names.tags.process: ${spring.application.name:application}:${random.value:0000}
service.name=Phil
metrics.names.tags.process=${spring.application.name:application}:${random.value:0000}

View File

@ -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>

View File

@ -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 {
this.name = name; this.name = name;
} }
public String getHelloMessage() {
return "Hello " + this.name;
}
} }

View File

@ -31,14 +31,18 @@ import org.springframework.web.bind.annotation.ResponseBody;
@Description("A controller for handling requests for hello messages") @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 {

View File

@ -24,11 +24,13 @@ import org.springframework.boot.actuate.metrics.export.MetricExportProperties;
import org.springframework.boot.actuate.metrics.jmx.JmxMetricWriter; import org.springframework.boot.actuate.metrics.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

View File

@ -1,7 +1,9 @@
service.name: Phil management.security.enabled=false
spring.metrics.export.redis.prefix: metrics.sample.${spring.metrics.export.aggregate.prefix}
spring.metrics.export.redis.key: keys.metrics.sample service.name=Phil
spring.metrics.export.aggregate.prefix: ${random.value:0000}.${spring.application.name:application} spring.metrics.export.redis.prefix=metrics.sample.${spring.metrics.export.aggregate.prefix}
spring.metrics.export.aggregate.key-pattern: d spring.metrics.export.redis.key=keys.metrics.sample
spring.jmx.default-domain: org.springframework.boot 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 spring.data.redis.repositories.enabled=false

View File

@ -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;

View File

@ -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 {

View File

@ -1 +1 @@
service.greeting: Hello service.greeting=Hello

View File

@ -24,10 +24,6 @@
<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-starter-actuator</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId> <artifactId>spring-boot-starter-tomcat</artifactId>

View File

@ -33,10 +33,6 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId> <artifactId>spring-boot-starter-jetty</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</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>

View File

@ -35,10 +35,6 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId> <artifactId>spring-boot-starter-jetty</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</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>

View File

@ -23,10 +23,6 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId> <artifactId>spring-boot-starter-websocket</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</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>

View File

@ -33,10 +33,6 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId> <artifactId>spring-boot-starter-undertow</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</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>