@ -15,7 +15,6 @@
@@ -15,7 +15,6 @@
* /
package org.springframework.platform.netflix.eureka ;
import javax.annotation.PostConstruct ;
import javax.annotation.PreDestroy ;
import org.slf4j.Logger ;
@ -25,8 +24,10 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
@@ -25,8 +24,10 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression ;
import org.springframework.boot.context.properties.EnableConfigurationProperties ;
import org.springframework.context.ApplicationListener ;
import org.springframework.context.SmartLifecycle ;
import org.springframework.context.annotation.Configuration ;
import org.springframework.context.event.ContextRefreshedEvent ;
import org.springframework.core.Ordered ;
import com.netflix.appinfo.ApplicationInfoManager ;
import com.netflix.appinfo.InstanceInfo.InstanceStatus ;
@ -43,10 +44,14 @@ import com.netflix.discovery.EurekaClientConfig;
@@ -43,10 +44,14 @@ import com.netflix.discovery.EurekaClientConfig;
@ConditionalOnClass ( EurekaClientConfig . class )
@ConditionalOnExpression ( "${eureka.client.enabled:true}" )
public class EurekaClientAutoConfiguration implements
ApplicationListener < ContextRefreshedEvent > {
ApplicationListener < ContextRefreshedEvent > , SmartLifecycle , Ordered {
private static final Logger logger = LoggerFactory . getLogger ( EurekaClientAutoConfiguration . class ) ;
private boolean running ;
private int order = 0 ;
@Autowired
private EurekaClientConfigBean clientConfig ;
@ -55,19 +60,49 @@ public class EurekaClientAutoConfiguration implements
@@ -55,19 +60,49 @@ public class EurekaClientAutoConfiguration implements
@Override
public void onApplicationEvent ( ContextRefreshedEvent event ) {
logger . info ( "Registering application {} with eureka with status UP" , instanceConfig . getAppname ( ) ) ;
logger . info ( "Registering application {} with eureka with status UP" , instanceConfig . getAppname ( ) ) ;
ApplicationInfoManager . getInstance ( ) . setInstanceStatus ( InstanceStatus . UP ) ;
}
@PostConstruct
public void init ( ) {
DiscoveryManager . getInstance ( ) . initComponent ( instanceConfig , clientConfig ) ;
}
@PreDestroy
public void close ( ) {
logger . info ( "Removing application {} from eureka" , instanceConfig . getAppname ( ) ) ;
DiscoveryManager . getInstance ( ) . shutdownComponent ( ) ;
}
@Override
public void start ( ) {
DiscoveryManager . getInstance ( ) . initComponent ( instanceConfig , clientConfig ) ;
}
@Override
public void stop ( ) {
running = false ;
}
@Override
public boolean isRunning ( ) {
return running ;
}
@Override
public int getPhase ( ) {
return 0 ;
}
@Override
public boolean isAutoStartup ( ) {
return true ;
}
@Override
public void stop ( Runnable callback ) {
callback . run ( ) ;
}
@Override
public int getOrder ( ) {
return order ;
}
}