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
在你的gradle文件中没有任何云相关......所以没有eurake客户端的jar文件,没有注册。 –
我已添加以下依赖项,但仍然没有运气编译'com.netflix.eureka:eureka-client:1.4.11' –
您正在遵循教程,然后按照教程进行操作......添加spring cloud eureka依赖项在教程中。 –