我对Netflix和SpringBoot非常陌生。我构建了一个非常简单的Eureka服务器和客户端,以了解他们是如何发现的。当我进入localhost:8761/时,Eureka服务器通常会加载自己的UI。
我正在使用Eclipse的Tomcat运行这两个实例。
我构建的尤里卡客户端没有代码,因为它只运行SpringBoot应用程序,并有适当的注释。尤里卡服务器也是一样的东西。
当我运行客户机时,在运行服务器之后,我会得到以下堆栈。我浏览了一下网络,想得到一些解释,但没有找到任何解释。您知道是什么导致了这些JSONObject异常吗?
服务器端堆栈:http://pastebin.ca/2968955
客户端堆栈:http://pastebin.ca/2968957
下面是我的代码:
EurekaServer.java:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
@EnableEurekaServer
public class EurekaServer {
public static void main( String[] args ) {
SpringApplication.run(EurekaServer.class, args);
}
}
EurekaServer的application.yml:
spring:
application:
name: EurekaServer
server:
port: 8761
eureka:
instance:
hostname: localhost
client:
registerWithEureka: false
festRegistry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
EurekaClientApp.java:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@EnableEurekaClient
@RestController
public class EurekaClientApp {
public static void main(String[] args) {
SpringApplication.run(EurekaClientApp.class, args);
}
}
EurekaClient的Application.yml:
spring:
application:
name: EurekaClient
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
registerWithEureka: true
fetchRegistry: false
instance:
leaseRenewalIntervalInSeconds: 10
metadataMap:
instanceId: ${spring.application.name}:${spring.application.instance_id:${random.value}}
server:
port: 8188
尤里卡-客户。属性:
eureka.port=8188
eureka.vipAddress=productservice.mydomain.net
eureka.preferSameZone=true
eureka.shouldUseDns=false
eureka.availabilityZones=default
eureka.serviceUrl.defaultZone=http://localhost:8761/eureka/
发布于 2015-04-09 12:38:31
因此,经过几个小时的失败尝试,通过修改代码使其正常工作,我查看了pom.xml文件,并删除了附加到应用程序这一部分的依赖项。我把它们一个接一个地放回去,验证它所做的修改,我发现我对eureka的依赖是错误的,因为我把我的com.netflix.eureka替换成了springboot提供的那个,比如spring-cloud-starter-eureka。
https://stackoverflow.com/questions/29494149
复制相似问题