add SampleProperties

This commit is contained in:
Spencer Gibb
2015-05-27 10:30:15 -06:00
parent edb147a268
commit 59ab3638d5
3 changed files with 46 additions and 0 deletions

View File

@@ -45,6 +45,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-consul-config</artifactId>

View File

@@ -22,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.bind.RelaxedPropertyResolver;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.bus.jackson.SubtypeModule;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
@@ -45,6 +46,7 @@ import org.springframework.web.bind.annotation.RestController;
@EnableDiscoveryClient
@EnableConsulUi
@RestController
@EnableConfigurationProperties
@Slf4j
public class SampleApplication implements ApplicationListener<SimpleRemoteEvent> {
@@ -78,11 +80,21 @@ public class SampleApplication implements ApplicationListener<SimpleRemoteEvent>
return property;
}
@RequestMapping("/prop")
public String prop() {
return sampleProperties().getProp();
}
@Bean
public SubtypeModule sampleSubtypeModule() {
return new SubtypeModule(SimpleRemoteEvent.class);
}
@Bean
public SampleProperties sampleProperties() {
return new SampleProperties();
}
public static void main(String[] args) {
SpringApplication.run(SampleApplication.class, args);
}

View File

@@ -0,0 +1,30 @@
/*
* Copyright 2013-2015 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 org.springframework.cloud.consul.sample;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* @author Spencer Gibb
*/
@ConfigurationProperties("sample")
@Data
public class SampleProperties {
private String prop = "default value";
}