Browse Source

Put @Bean EurekaServerConfig in nested class to avoid cycle

A new integration test ill be added in spring-cloud-samples/tests.

Fixes gh-759
pull/6/head
Dave Syer 9 years ago
parent
commit
b46dab3099
  1. 50
      spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaServerConfiguration.java

50
spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaServerConfiguration.java

@ -37,6 +37,7 @@ import org.springframework.boot.context.embedded.FilterRegistrationBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.client.actuator.HasFeatures; import org.springframework.cloud.client.actuator.HasFeatures;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EurekaConstants;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -72,9 +73,8 @@ public class EurekaServerConfiguration extends WebMvcConfigurerAdapter {
/** /**
* List of packages containing Jersey resources required by the Eureka server * List of packages containing Jersey resources required by the Eureka server
*/ */
private static String[] EUREKA_PACKAGES = new String[] { private static String[] EUREKA_PACKAGES = new String[] { "com.netflix.discovery",
"com.netflix.discovery", "com.netflix.eureka" };
"com.netflix.eureka"};
@Autowired @Autowired
private ApplicationInfoManager applicationInfoManager; private ApplicationInfoManager applicationInfoManager;
@ -105,13 +105,16 @@ public class EurekaServerConfiguration extends WebMvcConfigurerAdapter {
return HasFeatures.namedFeature("Eureka Server", EurekaServerConfiguration.class); return HasFeatures.namedFeature("Eureka Server", EurekaServerConfiguration.class);
} }
@Configuration
protected static class EurekaServerConfigBeanConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
public EurekaServerConfig eurekaServerConfig() { public EurekaServerConfig eurekaServerConfig() {
return new EurekaServerConfigBean(); return new EurekaServerConfigBean();
} }
}
//TODO: is there a better way? // TODO: is there a better way?
@Bean(name = "spring.http.encoding.CONFIGURATION_PROPERTIES") @Bean(name = "spring.http.encoding.CONFIGURATION_PROPERTIES")
public HttpEncodingProperties httpEncodingProperties() { public HttpEncodingProperties httpEncodingProperties() {
HttpEncodingProperties properties = new HttpEncodingProperties(); HttpEncodingProperties properties = new HttpEncodingProperties();
@ -122,48 +125,47 @@ public class EurekaServerConfiguration extends WebMvcConfigurerAdapter {
@Bean @Bean
@ConditionalOnProperty(prefix = "eureka.dashboard", name = "enabled", matchIfMissing = true) @ConditionalOnProperty(prefix = "eureka.dashboard", name = "enabled", matchIfMissing = true)
public EurekaController eurekaController() { public EurekaController eurekaController() {
return new EurekaController(applicationInfoManager); return new EurekaController(this.applicationInfoManager);
} }
@Bean @Bean
public ServerCodecs serverCodecs() { public ServerCodecs serverCodecs() {
return new DefaultServerCodecs(eurekaServerConfig); return new DefaultServerCodecs(this.eurekaServerConfig);
} }
@Bean @Bean
public PeerAwareInstanceRegistry peerAwareInstanceRegistry(ServerCodecs serverCodecs) { public PeerAwareInstanceRegistry peerAwareInstanceRegistry(
eurekaClient.getApplications(); // force initialization ServerCodecs serverCodecs) {
return new InstanceRegistry(eurekaServerConfig, eurekaClientConfig, serverCodecs, this.eurekaClient.getApplications(); // force initialization
eurekaClient, expectedNumberOfRenewsPerMin, defaultOpenForTrafficCount); return new InstanceRegistry(this.eurekaServerConfig, this.eurekaClientConfig,
serverCodecs, this.eurekaClient, this.expectedNumberOfRenewsPerMin,
this.defaultOpenForTrafficCount);
} }
@Bean @Bean
public PeerEurekaNodes peerEurekaNodes(PeerAwareInstanceRegistry registry, public PeerEurekaNodes peerEurekaNodes(PeerAwareInstanceRegistry registry,
ServerCodecs serverCodecs) { ServerCodecs serverCodecs) {
return new PeerEurekaNodes(registry, eurekaServerConfig, eurekaClientConfig, return new PeerEurekaNodes(registry, this.eurekaServerConfig,
serverCodecs, applicationInfoManager); this.eurekaClientConfig, serverCodecs, this.applicationInfoManager);
} }
@Bean @Bean
public EurekaServerContext eurekaServerContext(ServerCodecs serverCodecs, public EurekaServerContext eurekaServerContext(ServerCodecs serverCodecs,
PeerAwareInstanceRegistry registry, PeerAwareInstanceRegistry registry, PeerEurekaNodes peerEurekaNodes) {
PeerEurekaNodes peerEurekaNodes) { return new DefaultEurekaServerContext(this.eurekaServerConfig, serverCodecs,
return new DefaultEurekaServerContext(eurekaServerConfig, serverCodecs, registry, registry, peerEurekaNodes, this.applicationInfoManager);
peerEurekaNodes, applicationInfoManager);
} }
@Bean @Bean
public EurekaServerBootstrap eurekaServerBootstrap(PeerAwareInstanceRegistry registry, public EurekaServerBootstrap eurekaServerBootstrap(PeerAwareInstanceRegistry registry,
EurekaServerContext serverContext) { EurekaServerContext serverContext) {
return new EurekaServerBootstrap(applicationInfoManager, eurekaClientConfig, return new EurekaServerBootstrap(this.applicationInfoManager,
eurekaServerConfig, registry, serverContext); this.eurekaClientConfig, this.eurekaServerConfig, registry,
serverContext);
} }
/** /**
* Register the Jersey filter * Register the Jersey filter
*
* @param eurekaJerseyApp the jersey application
* @return
*/ */
@Bean @Bean
public FilterRegistrationBean jerseyFilterRegistration( public FilterRegistrationBean jerseyFilterRegistration(
@ -171,8 +173,8 @@ public class EurekaServerConfiguration extends WebMvcConfigurerAdapter {
FilterRegistrationBean bean = new FilterRegistrationBean(); FilterRegistrationBean bean = new FilterRegistrationBean();
bean.setFilter(new ServletContainer(eurekaJerseyApp)); bean.setFilter(new ServletContainer(eurekaJerseyApp));
bean.setOrder(Ordered.LOWEST_PRECEDENCE); bean.setOrder(Ordered.LOWEST_PRECEDENCE);
bean.setUrlPatterns(Collections bean.setUrlPatterns(
.singletonList(EurekaServerConfigBean.DEFAULT_PREFIX + "/*")); Collections.singletonList(EurekaConstants.DEFAULT_PREFIX + "/*"));
return bean; return bean;
} }
@ -211,7 +213,7 @@ public class EurekaServerConfiguration extends WebMvcConfigurerAdapter {
propsAndFeatures.put( propsAndFeatures.put(
// Skip static content used by the webapp // Skip static content used by the webapp
ServletContainer.PROPERTY_WEB_PAGE_CONTENT_REGEX, ServletContainer.PROPERTY_WEB_PAGE_CONTENT_REGEX,
EurekaServerConfigBean.DEFAULT_PREFIX + "/(fonts|images|css|js)/.*"); EurekaConstants.DEFAULT_PREFIX + "/(fonts|images|css|js)/.*");
DefaultResourceConfig rc = new DefaultResourceConfig(classes); DefaultResourceConfig rc = new DefaultResourceConfig(classes);
rc.setPropertiesAndFeatures(propsAndFeatures); rc.setPropertiesAndFeatures(propsAndFeatures);

Loading…
Cancel
Save