spring-cloud-netflix icon indicating copy to clipboard operation
spring-cloud-netflix copied to clipboard

@EnableDiscoveryClient does not working in traditional deployment

Open rozhok opened this issue 10 years ago • 5 comments

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,

rozhok avatar Jun 09 '15 16:06 rozhok

+1

floer32 avatar Jun 10 '15 00:06 floer32

I am having the same problem, how you solved?

ghzatomic avatar Jul 13 '15 21:07 ghzatomic

@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.

rozhok avatar Jul 14 '15 05:07 rozhok

@rozhok what were the errors?

spencergibb avatar Nov 11 '15 05:11 spencergibb

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

rozhok avatar Nov 11 '15 07:11 rozhok