2015-11-05 65 views
1

我有一個樣品尤里卡服務器項目,運行時無論是在的IntelliJ,或者用「MVN春季啓動:運行」工作正常。然而,直接與 「Java的罐子尤里卡服務器-1.0-SNAPSHOT.jar」 運行尤伯杯罐子的時候,我發現了以下堆棧跟蹤:春雲尤里卡:工作與Maven和IDE,但不作爲尤伯杯罐子

2015-11-04 19:48:56.985 ERROR 138300 --- [   main] o.s.boot.SpringApplication    : Application startup failed 

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [org.springframework.cloud.netflix.eureka.server.EurekaServerConfiguration]; nested exception is java.lang.IllegalStateException: Annotation @EnableDiscoveryClient found, but there are no implementations. Did you forget to include a starter? 
     at org.springframework.context.annotation.ConfigurationClassParser.processDeferredImportSelectors(ConfigurationClassParser.java:437) 
     at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:183) 
     at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:306) 
     at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:239) 
     at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:254) 
     at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:94) 
     at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:606) 
     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:462) 
     at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) 
     at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686) 
     at org.springframework.boot.SpringApplication.run(SpringApplication.java:320) 
     at org.springframework.boot.SpringApplication.run(SpringApplication.java:957) 
     at org.springframework.boot.SpringApplication.run(SpringApplication.java:946) 
     at com.my.example.EurekaApplication.main(EurekaApplication.java:20) 
Caused by: java.lang.IllegalStateException: Annotation @EnableDiscoveryClient found, but there are no implementations. Did you forget to include a starter? 
     at org.springframework.cloud.util.SpringFactoryImportSelector.selectImports(SpringFactoryImportSelector.java:75) 
     at org.springframework.context.annotation.ConfigurationClassParser.processDeferredImportSelectors(ConfigurationClassParser.java:429) 
     ... 13 common frames omitted 

這裏的POM文件:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.my.example</groupId> 
    <artifactId>eureka-server</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <packaging>jar</packaging> 

    <name>eureka-server</name> 

    <properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <java.version>1.8</java.version> 
    <start-class>com.my.example.EurekaApplication</start-class> 
    </properties> 

    <dependencies> 
    <dependency> 
     <groupId>org.springframework.cloud</groupId> 
     <artifactId>spring-cloud-starter-eureka-server</artifactId> 
     <version>1.0.3.RELEASE</version> 
     <exclusions> 
     <exclusion> 
      <groupId>com.sun.jersey</groupId> 
      <artifactId>jersey-servlet</artifactId> 
     </exclusion> 
     <exclusion> 
      <groupId>com.sun.jersey</groupId> 
      <artifactId>jersey-server</artifactId> 
     </exclusion> 
     </exclusions> 
    </dependency> 
    <!-- spring-cloud-starter-eureka-server 1.0.3 pulls conflicting jersey versions, 
    so we add 1.11 below and remove 1.13 in exclusions above --> 
    <dependency> 
     <groupId>com.sun.jersey</groupId> 
     <artifactId>jersey-servlet</artifactId> 
     <version>1.11</version> 
    </dependency> 
    <dependency> 
     <groupId>com.sun.jersey</groupId> 
     <artifactId>jersey-server</artifactId> 
     <version>1.11</version> 
    </dependency> 

    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>3.8.1</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-test</artifactId> 
     <version>1.2.4.RELEASE</version> 
     <scope>test</scope> 
    </dependency> 
    </dependencies> 

    <build> 
    <plugins> 
     <plugin> 
     <artifactId>maven-compiler-plugin</artifactId> 
     <version>3.3</version> 
     <configuration> 
      <source>1.8</source> 
      <target>1.8</target> 
     </configuration> 
     </plugin> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-shade-plugin</artifactId> 
     <version>2.3</version> 
     <executions> 
      <execution> 
      <phase>package</phase> 
      <goals> 
       <goal>shade</goal> 
      </goals> 
      <configuration> 
       <transformers> 
       <transformer 
         implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> 
        <mainClass>${start-class}</mainClass> 
       </transformer> 
       </transformers> 
      </configuration> 
      </execution> 
     </executions> 
     </plugin> 
     <plugin> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-maven-plugin</artifactId> 
     <version>1.2.4.RELEASE</version> 
     <configuration> 
      <mainClass>${start-class}</mainClass> 
      <addResources>true</addResources> 
     </configuration> 
     </plugin> 
    </plugins> 
    </build> 


</project> 

所以我有一個彈簧雲起動尤里卡服務器啓動的依賴,再加上我沒有@EnableDiscoveryClient標註在項目的任何地方。

這裏是整個項目唯一的.java文件:

@SpringBootApplication 
@EnableEurekaServer 
public class EurekaApplication 
{  
    public static void main(String[] args) { 
     SpringApplication.run(EurekaApplication.class, args);; 
    } 
} 

這裏是application.properties文件:

server.port=8761 
eureka.client.registerWithEureka: false 
eureka.client.fetchRegistry: false 
eureka.server.waitTimeInMsWhenSyncEmpty: 0 

預先感謝您!

+0

你爲什麼使用陰影插件?春季啓動插件應該爲你做所有這些。 – spencergibb

回答

3

尤里卡不會工作與您指定的球衣版本(它不適合我)。

使用http://start.spring.io生成啓動項目。

這pom.xml的確實工作。

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.my.example</groupId> 
    <artifactId>eureka-server</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <packaging>jar</packaging> 

    <name>eureka-server</name> 

    <parent> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-parent</artifactId> 
     <version>1.2.7.RELEASE</version> 
     <relativePath/> <!-- lookup parent from repository --> 
    </parent> 

    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
     <java.version>1.8</java.version> 
    </properties> 

    <dependencies> 
     <dependency> 
      <groupId>org.springframework.cloud</groupId> 
      <artifactId>spring-cloud-starter-eureka-server</artifactId> 
     </dependency> 

     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-test</artifactId> 
      <scope>test</scope> 
     </dependency> 
    </dependencies> 

    <dependencyManagement> 
     <dependencies> 
      <dependency> 
       <groupId>org.springframework.cloud</groupId> 
       <artifactId>spring-cloud-starter-parent</artifactId> 
       <version>Angel.SR3</version> 
       <type>pom</type> 
       <scope>import</scope> 
      </dependency> 
     </dependencies> 
    </dependencyManagement> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.springframework.boot</groupId> 
       <artifactId>spring-boot-maven-plugin</artifactId> 
      </plugin> 
     </plugins> 
    </build> 

</project> 
+0

謝謝斯賓塞,但這並沒有幫助(相同的問題)。 1.0.3是最新的穩定版本嗎?哪一種彈簧啓動版本應該與1.0.3一起使用? – Turar

+0

謝謝斯賓塞。我沒有得到它的工作在本週早些時候 - 我只是缺少彈簧引導Maven的插件內的「改頭換面」的執行目標,是的,我也擺脫了遮陽插件。但是,你的版本更清潔,也有效。非常感謝您的幫助! – Turar

+0

謝謝你斯賓塞!它效果很好。只是一個評論(關於你的建議),我真的認爲這是一個偉大的想法(使用http://start.spring.io上手的基礎上,至少,pom.xml中,等等),但是,可惜的是我做到了,希望一切都能正常工作,事實上並沒有......這是另一個錯誤,但它沒有奏效。無論如何,感謝您分享您的經驗,確實您的POM運作良好。 –