Spring boot 微服务未在Eureka注册
我刚刚读了下面的文章 但我无法让我的微服务在eureka注册 客户服务部Spring boot 微服务未在Eureka注册,spring-boot,netflix-eureka,Spring Boot,Netflix Eureka,我刚刚读了下面的文章 但我无法让我的微服务在eureka注册 客户服务部 # 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 rep
# 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);
}
}
对于可能有相同问题的其他人,服务上的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'
}
你的gradle文件中没有与云相关的内容。。。因此,没有eurake客户端JAR,没有注册。我添加了以下依赖项,但仍然没有编译'com.netflix.eureka:eureka客户端:1.4.11'。您正在学习教程,然后学习教程。。。添加spring cloud eureka依赖项,如本教程中所述。
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'
}