spring-cloud / spring-cloud-netflix

Integration with Netflix OSS components
http://cloud.spring.io/spring-cloud-netflix/
Apache License 2.0
4.87k stars 2.44k forks source link

@EnableDiscoveryClient does not working in traditional deployment #387

Open rozhok opened 9 years ago

rozhok commented 9 years ago

Have application

@SpringBootApplication
@EnableDiscoveryClient
@EnableAutoConfiguration
public class PortalApplication extends SpringBootServletInitializer {

    private static final Logger LOG = LoggerFactory.getLogger(PortalApplication.class);

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        LOG.info("Init web app");
        return application.sources(PortalApplication.class);
    }

    public static void main(String[] args) {
        LOG.info("Running app");
        SpringApplication.run(PortalApplication.class, args);
    }

}

When running using gradle bootRun everything works fine and Eureka client initializes properly. But when I'm try to deploy war into standalone Tomcat server, Eureka client did not initializes. Tried all the combinations of annotations with no luck.

Gradle config:

buildscript {
    ext {
        springBootVersion = '1.2.4.RELEASE'
    }
    repositories {
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath("io.spring.gradle:dependency-management-plugin:0.5.1.RELEASE")
    }
}

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'war'
apply plugin: 'io.spring.dependency-management'

springBoot {
    requiresUnpack = ['com.netflix.eureka:eureka-core', 'com.netflix.eureka:eureka-client']
}

jar {
    baseName = 'portal-service'
    version = '0.0.1-SNAPSHOT'
}

war {
    baseName = 'portal-service'
//    version = '0.0.1-SNAPSHOT-' + System.currentTimeMillis();
    version = '0.0.1-SNAPSHOT';
}

sourceCompatibility = 1.8
targetCompatibility = 1.8
group = 'demo'
mainClassName = 'com.demo.portal.PortalApplication'

repositories {
    mavenCentral()
    maven { url "http://repo.spring.io/libs-snapshot" }
}

configurations {
    providedRuntime
}

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web") {
//        exclude module: 'spring-boot-starter-tomcat'
    }
    compile('org.springframework.cloud:spring-cloud-starter-eureka')
    compile('org.springframework.cloud:spring-cloud-starter-eureka-server:1.0.0.RELEASE') {
        exclude(module: 'servlet-api')
    }

    compile("org.springframework.boot:spring-boot-starter-web")
    providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")

    testCompile('org.springframework.boot:spring-boot-starter-test')
}

dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-starter-parent:1.0.2.RELEASE"
    }
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.4'
}

Think there is some issues with classpath but don't know where to start looking.

Same app but with EurekaServer works fine somehow.

This issue was moved from spring-projects/spring-boot#3161

Thanks,

floer32 commented 9 years ago

+1

ghzatomic commented 9 years ago

I am having the same problem, how you solved?

rozhok commented 9 years ago

@ghzatomic I used Docker containers with Beanstalk so Spring Boot runs in embedded server and all works pretty fine except of proper hostname resolving problem described here: #30 So I created my own EurekaInstanceConfiguration with some AWS-specific stuff inside it and it worked fine.

spencergibb commented 9 years ago

@rozhok what were the errors?

rozhok commented 9 years ago

@spencergibb as far as I remember, there wasn't any errors, client just was unable to connect to peer.