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 ...@@ -38,6 +38,7 @@ public class EurekaClientAutoConfiguration implements ApplicationListener<Contex
@Autowired @Autowired
private EurekaClientConfigBean clientConfig; private EurekaClientConfigBean clientConfig;
@Autowired @Autowired
private EurekaInstanceConfigBean instanceConfig; private EurekaInstanceConfigBean instanceConfig;
......
...@@ -27,6 +27,7 @@ import lombok.Setter; ...@@ -27,6 +27,7 @@ import lombok.Setter;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import com.netflix.appinfo.DataCenterInfo; import com.netflix.appinfo.DataCenterInfo;
...@@ -45,12 +46,14 @@ public class EurekaInstanceConfigBean implements EurekaInstanceConfig { ...@@ -45,12 +46,14 @@ public class EurekaInstanceConfigBean implements EurekaInstanceConfig {
@Getter(AccessLevel.PRIVATE) @Setter(AccessLevel.PRIVATE) @Getter(AccessLevel.PRIVATE) @Setter(AccessLevel.PRIVATE)
private String[] hostInfo = initHostInfo(); private String[] hostInfo = initHostInfo();
@Value("${spring.application.name:unkown}")
private String appname = "unknown"; private String appname = "unknown";
private String appGroupName; private String appGroupName;
private boolean instanceEnabledOnit; private boolean instanceEnabledOnit;
@Value("${server.port:80}")
private int nonSecurePort = 80; private int nonSecurePort = 80;
private int securePort = 443; private int securePort = 443;
...@@ -63,6 +66,7 @@ public class EurekaInstanceConfigBean implements EurekaInstanceConfig { ...@@ -63,6 +66,7 @@ public class EurekaInstanceConfigBean implements EurekaInstanceConfig {
private int leaseExpirationDurationInSeconds = 90; private int leaseExpirationDurationInSeconds = 90;
@Value("${spring.application.name:unkown}.mydomain.net")
private String virtualHostName; private String virtualHostName;
private String secureVirtualHostName; private String secureVirtualHostName;
......
...@@ -8,14 +8,3 @@ eureka: ...@@ -8,14 +8,3 @@ eureka:
serviceUrl: serviceUrl:
defaultZone: http://localhost:8080/v2/ defaultZone: http://localhost:8080/v2/
default.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