首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >微服务未向Eureka注册

微服务未向Eureka注册
EN

Stack Overflow用户
提问于 2016-08-25 17:18:27
回答 1查看 2.4K关注 0票数 2

我刚刚关注了下面的文章https://spring.io/blog/2015/07/14/microservices-with-spring,但是我不能让我的微服务注册到eureka。

customer-service.yml

代码语言:javascript
复制
# 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

代码语言:javascript
复制
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

代码语言:javascript
复制
@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);
    }
}

registration-server.yml

代码语言:javascript
复制
# 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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-08-25 19:00:09

对于其他可能有同样问题的人,服务上的build.gradle应该看起来像下面的那个。

代码语言:javascript
复制
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'
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39141278

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档