Commit 8b199c5c by Dave Syer

Use Environment for defaulting app name and port

parent 5ee8c8c8
Ths project provides Netflix OSS integrations for Spring Boot apps through autoconfiguration
and binding to the Spring Environment and other Spring programming model idioms.
# Eureka Clients
Example eureka client:
```
@Configuration
@ComponentScan
@EnableAutoConfiguration
@RestController
public class Application {
@RequestMapping("/")
public String home() {
return "Hello world";
}
public static void main(String[] args) {
new SpringApplicationBuilder(Application.class).web(true).run(args);
}
}
```
(i.e. utterly normal Spring Boot app). Configuration is required to locate the Eureka server. Example:
```
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8080/v2/
default.defaultZone: http://localhost:8080/v2/
```
The default application name, virtual host and non-secure port are taken from the `Environment` is
`${spring.application.name}`, `${spring.application.name}.mydomain.net` and `${server.port}` respectively.
......@@ -38,6 +38,7 @@ public class EurekaClientAutoConfiguration implements ApplicationListener<Contex
@Autowired
private EurekaClientConfigBean clientConfig;
@Autowired
private EurekaInstanceConfigBean instanceConfig;
......
......@@ -27,6 +27,7 @@ import lombok.Setter;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import com.netflix.appinfo.DataCenterInfo;
......@@ -45,12 +46,14 @@ public class EurekaInstanceConfigBean implements EurekaInstanceConfig {
@Getter(AccessLevel.PRIVATE) @Setter(AccessLevel.PRIVATE)
private String[] hostInfo = initHostInfo();
@Value("${spring.application.name:unkown}")
private String appname = "unknown";
private String appGroupName;
private boolean instanceEnabledOnit;
@Value("${server.port:80}")
private int nonSecurePort = 80;
private int securePort = 443;
......@@ -63,6 +66,7 @@ public class EurekaInstanceConfigBean implements EurekaInstanceConfig {
private int leaseExpirationDurationInSeconds = 90;
@Value("${spring.application.name:unkown}.mydomain.net")
private String virtualHostName;
private String secureVirtualHostName;
......
......@@ -8,14 +8,3 @@ eureka:
serviceUrl:
defaultZone: http://localhost:8080/v2/
default.defaultZone: http://localhost:8080/v2/
region: default
availabilityZones:
us-east-1: default
preferSameZoneEureka: true
useDnsForFetchingServiceUrls: false
instance:
nonSecurePort: ${server.port}
appname: ${spring.application.name}
virtualHostName: ${spring.application.name}.mydomain.net
statusPageUrlPath: /info
healthCheckUrlPath: /health
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment