- 用orbitz.consul client 端来获取
代码如下:
package com.yj.consul.client.consulClient;
import com.orbitz.consul.AgentClient;
import com.orbitz.consul.Consul;
public class App
{
public static void main( String[] args )
{
Consul consul = Consul.builder().build();
AgentClient agentClient = consul.agentClient();
System.out.println(agentClient.getAgent().getConfig().getDatacenter());
}
}
问题:
Exception in thread "main" java.lang.RuntimeException: java.lang.ClassNotFoundException: org.glassfish.jersey.client.JerseyClientBuilder
at javax.ws.rs.client.ClientBuilder.newBuilder(ClientBuilder.java:103)
at com.orbitz.consul.Consul$Builder.<init>(Consul.java:228)
at com.orbitz.consul.Consul.builder(Consul.java:218)
at com.yj.consul.client.consulClient.App.main(App.java:19)
Caused by: java.lang.ClassNotFoundException: org.glassfish.jersey.client.JerseyClientBuilder
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at javax.ws.rs.client.FactoryFinder.newInstance(FactoryFinder.java:115)
at javax.ws.rs.client.FactoryFinder.find(FactoryFinder.java:225)
at javax.ws.rs.client.ClientBuilder.newBuilder(ClientBuilder.java:86)
... 3 more
问题是,缺少org.glassfish.jersey.client.JerseyClientBuilder的包
pom文件中引入
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.17</version>
</dependency>
问题解决
网友评论