2016-08-25 83 views
2

我刚刚按照以下文章https://spring.io/blog/2015/07/14/microservices-with-spring ,但我不能让我的微服务注册尤里卡。微服务未注册尤里卡

客户service.yml

# Spring properties 
spring: 
    application: 
    name: customer-service 
    data: 
    mongodb: 
     host: 192.168.99.100 
     port: 32768 
     uri: mongodb://192.168.99.100:32768 
     database: customer 
     repositories: 
     enabled: true 

# Discovery Server Access 
eureka: 
    client: 
    serviceUrl: 
     defaultZone: http://127.0.0.1:1111/eureka/ 

# HTTP Server 
server: 
    port: 2222 # HTTP (Tomcat) port 

的build.gradle用于客户服务

group 'com.company' 
version '1.0-SNAPSHOT' 

apply plugin: 'java' 

sourceCompatibility = 1.5 

repositories { 
    mavenCentral() 
} 

dependencies { 
    compile 'org.springframework.boot:spring-boot-starter-web:1.4.0.RELEASE' 
    compile 'org.springframework.data:spring-data-mongodb:1.9.2.RELEASE' 
    testCompile group: 'junit', name: 'junit', version: '4.11' 
} 

CustomerService.java

@SpringBootApplication 
@EnableDiscoveryClient 
@RestController 
public class CustomerService { 

    @Autowired 
    CustomerRepository repository; 

    @RequestMapping("/") 
    @ResponseBody 
    List<Customer> get() { 
     return repository.findAll(); 
    } 


    @RequestMapping(value = "/", method = RequestMethod.POST) 
    void post(@RequestBody @Valid Customer customer, BindingResult bindingResult, Model model) { 
     repository.save(customer); 
    } 

    public static void main(String[] args) { 
     // Will configure using accounts-server.yml 
     System.setProperty("spring.config.name", "customer-service"); 

     SpringApplication.run(CustomerService.class, args); 
    } 
} 

登记-server.yml

# Configure this Discovery Server 
eureka: 
    instance: 
    hostname: 127.0.0.1 
    client: # Not a client, don't register with yourself 
    registerWithEureka: false 
    fetchRegistry: false 
    serviceUrl: 
     defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ 

server: 
    port: 1111 # HTTP (Tomcat) port 
+0

在你的gradle文件中没有任何云相关......所以没有eurake客户端的jar文件,没有注册。 –

+0

我已添加以下依赖项,但仍然没有运气编译'com.netflix.eureka:eureka-client:1.4.11' –

+0

您正在遵循教程,然后按照教程进行操作......添加spring cloud eureka依赖项在教程中。 –

回答

0

对于任何可能有相同问题的人,build.gradle服务应该看起来像下面那样。

version '1.0-SNAPSHOT' 

buildscript { 
    ext { 
     springBootVersion = '1.4.0.RELEASE' 
    } 
    repositories { 
     mavenCentral() 
    } 
    dependencies { 
     classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 
    } 
} 

apply plugin: 'java' 
apply plugin: 'idea' 
apply plugin: 'spring-boot' 


sourceCompatibility = 1.8 
targetCompatibility = 1.8 

repositories { 
    mavenCentral() 
} 

dependencyManagement { 
    imports { 
     mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Brixton.RELEASE' 
    } 
} 
dependencies { 
    compile('org.springframework.cloud:spring-cloud-starter-eureka') 
    compile 'org.springframework.boot:spring-boot-starter-web:1.4.0.RELEASE' 
    compile 'org.springframework.data:spring-data-mongodb:1.9.2.RELEASE' 

    testCompile group: 'junit', name: 'junit', version: '4.11' 
} 
相关问题