Сначала немного фона, я пытаюсь создать приложение RESTfull в Eclipse, и я преподаю сам DropWizard на куски с помощью формата PDF книгу доступной здесь: https://github.com/adhulappanavar/Dropwizard/blob/master/RESTful%20Web%20Services%20with%20Dropwizard%20%5BeBook%5D.pdfDropwizard несоответствие типа клиент
книг около двух лет из-за этого было несколько ошибок, из-за которых я столкнулся с этим, но следующая ошибка из моего класса ввода приложения (rappApplication) действительно превзошла меня.
Exception in thread "main" java.lang.ClassCastException: org.glassfish.jersey.client.JerseyClient cannot be cast to com.sun.jersey.api.client.Client
at edu.udel.rapp.rapp.rappApplication.run(rappApplication.java:50)
at edu.udel.rapp.rapp.rappApplication.run(rappApplication.java:1)
at io.dropwizard.cli.EnvironmentCommand.run(EnvironmentCommand.java:43)
at io.dropwizard.cli.ConfiguredCommand.run(ConfiguredCommand.java:85)
at io.dropwizard.cli.Cli.run(Cli.java:75)
at io.dropwizard.Application.run(Application.java:79)
at edu.udel.rapp.rapp.rappApplication.main(rappApplication.java:31)
В этом классе:
import io.dropwizard.Application;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;
import org.skife.jdbi.v2.DBI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.dropwizard.Application;
import io.dropwizard.Configuration;
import io.dropwizard.client.JerseyClientBuilder;
import io.dropwizard.jdbi.DBIFactory;
import edu.udel.rapp.resources.ClientResource;
import edu.udel.rapp.resources.StudentResource;
import com.sun.jersey.api.client.Client;
public class rappApplication extends Application<rappConfiguration> {
private static final Logger LOGGER =
LoggerFactory.getLogger(rappApplication.class);
public static void main(final String[] args) throws Exception {
new rappApplication().run(args);
}
@Override
public String getName() {
return "rapp";
}
@Override
public void initialize(final Bootstrap<rappConfiguration> bootstrap) {
// TODO: application initialization
}
@Override
public void run(rappConfiguration c, Environment e) throws Exception {
final Client client = new JerseyClientBuilder(e).build("REST Client");
e.jersey().register(new ClientResource(client));
LOGGER.info("Method App#run() called");
for (int i=0; i < c.getMessageRepetitions(); i++) {
System.out.println(c.getMessage());
}
System.out.println(c.getAdditionalMessage());
// Create a DBI factory and build a JDBI instance
final DBIFactory factory = new DBIFactory();
final DBI jdbi = factory.build(e, c.getDataSourceFactory(), "mysql");
// Add the resource to the environment
e.jersey().register(new StudentResource(jdbi, e.getValidator()));
}
}
Теперь в книге инициализации клиента в моем методе выполнения не требуют литья Клиенту, но Eclipse, дает мне ошибку компиляции (» Тип несоответствия: невозможно преобразовать из javax.ws.rs.client.Client в com.sun.jersey.api.client.Client "), если я не отсылаю к клиенту там ... который затем вызывает ошибку во время выполнения.
Кроме того, я смущен, почему у Eclipse возникает проблема с «org.glassfish.jersey.client.JerseyClient», когда то, что я импортировал для моего класса, было io.dropwizard.client.JerseyClientBuilder;
Это почти похоже на то, что Eclipse смущен относительно того, что на самом деле является Клиентом.
правок: Я использую Maven со следующими зависимостями в моем pom.xml,
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.6.7</version>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-testing</artifactId>
<version>${dropwizard.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-client</artifactId>
<version>${dropwizard.version}</version>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-assets</artifactId>
<version>${dropwizard.version}</version>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-forms</artifactId>
<version>${dropwizard.version}</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.190</version>
</dependency>
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
<version>1.22.0</version>
</dependency>
<dependency>
<groupId>com.google.oauth-client</groupId>
<artifactId>google-oauth-client-jetty</artifactId>
<version>1.22.0</version>
</dependency>
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-drive</artifactId>
<version>v3-rev32-1.22.0</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-jdbi</artifactId>
<version>${dropwizard.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.sun.jersey/jersey-core -->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<version>1.8</version>
</dependency>
</dependencies>
Performing MVN чистую зависимость: дерево дал следующий результат
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building rapp 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ rapp ---
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ rapp ---
[INFO] edu.udel.rapp:rapp:jar:0.0.1-SNAPSHOT
[INFO] +- junit:junit:jar:3.8.1:test
[INFO] +- com.fasterxml.jackson.core:jackson-core:jar:2.6.7:compile
[INFO] +- io.dropwizard:dropwizard-testing:jar:1.0.4:test
[INFO] | +- io.dropwizard:dropwizard-core:jar:1.0.4:compile
[INFO] | | +- io.dropwizard:dropwizard-util:jar:1.0.4:compile
[INFO] | | | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.7.8:compile
[INFO] | | | +- com.google.guava:guava:jar:19.0:compile
[INFO] | | | \- joda-time:joda-time:jar:2.9.4:compile
[INFO] | | +- io.dropwizard:dropwizard-jackson:jar:1.0.4:compile
[INFO] | | | +- com.fasterxml.jackson.core:jackson-databind:jar:2.7.8:compile
[INFO] | | | +- com.fasterxml.jackson.datatype:jackson-datatype-guava:jar:2.7.8:compile
[INFO] | | | +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.7.8:compile
[INFO] | | | +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.7.8:compile
[INFO] | | | +- com.fasterxml.jackson.module:jackson-module-afterburner:jar:2.7.8:compile
[INFO] | | | \- com.fasterxml.jackson.datatype:jackson-datatype-joda:jar:2.7.8:compile
[INFO] | | +- io.dropwizard:dropwizard-validation:jar:1.0.4:compile
[INFO] | | | +- org.hibernate:hibernate-validator:jar:5.2.4.Final:compile
[INFO] | | | | +- org.jboss.logging:jboss-logging:jar:3.2.1.Final:compile
[INFO] | | | | \- com.fasterxml:classmate:jar:1.1.0:compile
[INFO] | | | \- org.glassfish:javax.el:jar:3.0.0:compile
[INFO] | | +- io.dropwizard:dropwizard-configuration:jar:1.0.4:compile
[INFO] | | | +- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:jar:2.7.8:compile
[INFO] | | | | \- org.yaml:snakeyaml:jar:1.15:compile
[INFO] | | | \- org.apache.commons:commons-lang3:jar:3.4:compile
[INFO] | | +- io.dropwizard:dropwizard-logging:jar:1.0.4:compile
[INFO] | | | +- io.dropwizard.metrics:metrics-logback:jar:3.1.2:compile
[INFO] | | | +- org.slf4j:jul-to-slf4j:jar:1.7.21:compile
[INFO] | | | +- ch.qos.logback:logback-core:jar:1.1.7:compile
[INFO] | | | +- org.slf4j:log4j-over-slf4j:jar:1.7.21:compile
[INFO] | | | +- org.slf4j:jcl-over-slf4j:jar:1.7.21:compile
[INFO] | | | \- org.eclipse.jetty:jetty-util:jar:9.3.9.v20160517:compile
[INFO] | | +- io.dropwizard:dropwizard-metrics:jar:1.0.4:compile
[INFO] | | +- io.dropwizard:dropwizard-jersey:jar:1.0.4:compile
[INFO] | | | +- org.glassfish.jersey.ext:jersey-metainf-services:jar:2.23.2:compile
[INFO] | | | +- org.glassfish.jersey.ext:jersey-bean-validation:jar:2.23.2:compile
[INFO] | | | +- io.dropwizard.metrics:metrics-jersey2:jar:3.1.2:compile
[INFO] | | | +- com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:jar:2.7.8:compile
[INFO] | | | | +- com.fasterxml.jackson.jaxrs:jackson-jaxrs-base:jar:2.7.8:compile
[INFO] | | | | \- com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.7.8:compile
[INFO] | | | +- org.glassfish.jersey.containers:jersey-container-servlet:jar:2.23.2:compile
[INFO] | | | +- org.eclipse.jetty:jetty-server:jar:9.3.9.v20160517:compile
[INFO] | | | | +- javax.servlet:javax.servlet-api:jar:3.1.0:compile
[INFO] | | | | \- org.eclipse.jetty:jetty-io:jar:9.3.9.v20160517:compile
[INFO] | | | +- org.eclipse.jetty:jetty-webapp:jar:9.3.9.v20160517:compile
[INFO] | | | | \- org.eclipse.jetty:jetty-xml:jar:9.3.9.v20160517:compile
[INFO] | | | \- org.eclipse.jetty:jetty-continuation:jar:9.3.9.v20160517:compile
[INFO] | | +- io.dropwizard:dropwizard-jetty:jar:1.0.4:compile
[INFO] | | | +- io.dropwizard.metrics:metrics-jetty9:jar:3.1.2:compile
[INFO] | | | +- org.eclipse.jetty:jetty-servlet:jar:9.3.9.v20160517:compile
[INFO] | | | | \- org.eclipse.jetty:jetty-security:jar:9.3.9.v20160517:compile
[INFO] | | | +- org.eclipse.jetty:jetty-servlets:jar:9.3.9.v20160517:compile
[INFO] | | | \- org.eclipse.jetty:jetty-http:jar:9.3.9.v20160517:compile
[INFO] | | +- io.dropwizard:dropwizard-lifecycle:jar:1.0.4:compile
[INFO] | | +- io.dropwizard.metrics:metrics-core:jar:3.1.2:compile
[INFO] | | +- io.dropwizard.metrics:metrics-jvm:jar:3.1.2:compile
[INFO] | | +- io.dropwizard.metrics:metrics-servlets:jar:3.1.2:compile
[INFO] | | | \- io.dropwizard.metrics:metrics-json:jar:3.1.2:compile
[INFO] | | +- io.dropwizard.metrics:metrics-healthchecks:jar:3.1.2:compile
[INFO] | | +- io.dropwizard:dropwizard-request-logging:jar:1.0.4:compile
[INFO] | | | \- ch.qos.logback:logback-access:jar:1.1.7:compile
[INFO] | | +- net.sourceforge.argparse4j:argparse4j:jar:0.7.0:compile
[INFO] | | \- org.eclipse.jetty.toolchain.setuid:jetty-setuid-java:jar:1.0.3:compile
[INFO] | +- org.mockito:mockito-core:jar:2.0.54-beta:test
[INFO] | | \- net.bytebuddy:byte-buddy:jar:1.3.16:test
[INFO] | +- org.objenesis:objenesis:jar:2.3:test
[INFO] | +- org.assertj:assertj-core:jar:3.4.1:test
[INFO] | \- org.glassfish.jersey.test-framework.providers:jersey-test-framework-provider-inmemory:jar:2.23.2:test
[INFO] | +- org.glassfish.jersey.test-framework:jersey-test-framework-core:jar:2.23.2:test
[INFO] | | \- org.glassfish.jersey.containers:jersey-container-servlet-core:jar:2.23.2:compile
[INFO] | \- org.ow2.asm:asm-debug-all:jar:5.0.4:test
[INFO] +- io.dropwizard:dropwizard-client:jar:1.0.4:compile
[INFO] | +- org.glassfish.jersey.core:jersey-client:jar:2.23.2:compile
[INFO] | +- org.apache.httpcomponents:httpclient:jar:4.5.2:compile
[INFO] | | +- org.apache.httpcomponents:httpcore:jar:4.4.4:compile
[INFO] | | \- commons-codec:commons-codec:jar:1.9:compile
[INFO] | +- io.dropwizard.metrics:metrics-httpclient:jar:3.1.2:compile
[INFO] | \- org.glassfish.jersey.connectors:jersey-apache-connector:jar:2.23.2:compile
[INFO] +- io.dropwizard:dropwizard-assets:jar:1.0.4:compile
[INFO] | \- io.dropwizard:dropwizard-servlets:jar:1.0.4:compile
[INFO] | +- org.slf4j:slf4j-api:jar:1.7.21:compile
[INFO] | +- io.dropwizard.metrics:metrics-annotation:jar:3.1.2:compile
[INFO] | \- ch.qos.logback:logback-classic:jar:1.1.7:compile
[INFO] +- io.dropwizard:dropwizard-forms:jar:1.0.4:compile
[INFO] | \- org.glassfish.jersey.media:jersey-media-multipart:jar:2.23.2:compile
[INFO] | \- org.jvnet.mimepull:mimepull:jar:1.9.6:compile
[INFO] +- com.h2database:h2:jar:1.4.190:compile
[INFO] +- com.google.api-client:google-api-client:jar:1.22.0:compile
[INFO] | +- com.google.oauth-client:google-oauth-client:jar:1.22.0:compile
[INFO] | | +- com.google.http-client:google-http-client:jar:1.22.0:compile
[INFO] | | \- com.google.code.findbugs:jsr305:jar:1.3.9:compile
[INFO] | +- com.google.http-client:google-http-client-jackson2:jar:1.22.0:compile
[INFO] | \- com.google.guava:guava-jdk5:jar:17.0:compile
[INFO] +- com.google.oauth-client:google-oauth-client-jetty:jar:1.22.0:compile
[INFO] | +- com.google.oauth-client:google-oauth-client-java6:jar:1.22.0:compile
[INFO] | \- org.mortbay.jetty:jetty:jar:6.1.26:compile
[INFO] | +- org.mortbay.jetty:jetty-util:jar:6.1.26:compile
[INFO] | \- org.mortbay.jetty:servlet-api:jar:2.5-20081211:compile
[INFO] +- com.google.apis:google-api-services-drive:jar:v3-rev32-1.22.0:compile
[INFO] +- mysql:mysql-connector-java:jar:5.1.6:compile
[INFO] +- io.dropwizard:dropwizard-jdbi:jar:1.0.4:compile
[INFO] | +- io.dropwizard:dropwizard-db:jar:1.0.4:compile
[INFO] | | \- org.apache.tomcat:tomcat-jdbc:jar:8.5.3:compile
[INFO] | | \- org.apache.tomcat:tomcat-juli:jar:8.5.3:compile
[INFO] | +- org.jdbi:jdbi:jar:2.73:compile
[INFO] | \- io.dropwizard.metrics:metrics-jdbi:jar:3.1.2:compile
[INFO] +- org.glassfish.jersey.core:jersey-server:jar:2.11:compile
[INFO] | +- org.glassfish.jersey.core:jersey-common:jar:2.11:compile
[INFO] | | +- org.glassfish.jersey.bundles.repackaged:jersey-guava:jar:2.11:compile
[INFO] | | \- org.glassfish.hk2:osgi-resource-locator:jar:1.0.1:compile
[INFO] | +- javax.ws.rs:javax.ws.rs-api:jar:2.0:compile
[INFO] | +- javax.annotation:javax.annotation-api:jar:1.2:compile
[INFO] | +- org.glassfish.hk2:hk2-api:jar:2.3.0-b05:compile
[INFO] | | +- org.glassfish.hk2:hk2-utils:jar:2.3.0-b05:compile
[INFO] | | \- org.glassfish.hk2.external:aopalliance-repackaged:jar:2.3.0-b05:compile
[INFO] | +- org.glassfish.hk2.external:javax.inject:jar:2.3.0-b05:compile
[INFO] | +- org.glassfish.hk2:hk2-locator:jar:2.3.0-b05:compile
[INFO] | | \- org.javassist:javassist:jar:3.18.1-GA:compile
[INFO] | \- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] \- com.sun.jersey:jersey-core:jar:1.8:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
Это явная проблема несовпадения зависимость. Пожалуйста, объясните, какой инструмент сборки вы используете, и укажите используемые зависимости. – code
@code только что обновил мой op – VivaLebowski
Похож на конфликт зависимости с джерси-сердечником. Убедитесь, что вы исключаете эту зависимость из всех других зависимостей, чтобы гарантировать, что какая-либо другая версия не используется во время выполнения. – code