spring-cloud / spring-cloud/spring-cloud-netflix

@EnableDiscoveryClient does not working in traditional deployment

Open
#387 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

icebox
Dominant language
Java
Stars
5k
Forks
2.5k
Avg merge
1d 2h
Merged PRs (30d)
10

Description

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,

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with PortalApplication and the Gradle build configuration, comparing the bootRun classpath with the WAR deployed to standalone Tomcat. Investigate how the Eureka client dependency and provided Tomcat runtime are packaged and initialized in the traditional deployment. Done means the deployed WAR initializes the Eureka client as bootRun does.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring-boot
Domain
backend, cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.