dropwizard和hive jdbc之间不兼容

m528fe3b  于 2021-05-29  发布在  Hadoop
关注(0)|答案(1)|浏览(457)

我正在尝试使用dropwizard创建ws-rest,以获取查询的配置单元结果并以xml格式显示。每个分离的部分都可以毫无错误地完成。
当我加入所有东西时,我发现dropwizard和hivejdbc之间不兼容。显然,hivejdbc有jersey 1作为依赖项,dropwizard有jersey 2。
我不确定这是不是问题所在。我试图排除pom.xml中的依赖关系,但没有解决。
我试图让一个应用程序只是将hivejdbc作为依赖项放在pom.xml文件中,而不使用或导入代码的任何部分,错误仍然在发生。
pom.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

    <prerequisites>
        <maven>3.0.0</maven>
    </prerequisites>

    <modelVersion>4.0.0</modelVersion>
    <groupId>test</groupId>
    <artifactId>ws-test</artifactId>
    <version>1.0.0</version>
    <name>ws-test</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <dropwizard.version>1.0.5</dropwizard.version>
        <mainClass>test.TestApp</mainClass>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>io.dropwizard</groupId>
                <artifactId>dropwizard-bom</artifactId>
                <version>${dropwizard.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>io.dropwizard</groupId>
            <artifactId>dropwizard-core</artifactId>
        </dependency>
        <dependency>
            <groupId>io.dropwizard</groupId>
            <artifactId>dropwizard-forms</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.hive</groupId>
            <artifactId>hive-jdbc</artifactId>
            <version>1.1.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-core</artifactId>
            <version>1.2.1</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.4.1</version>
                <configuration>
                    <createDependencyReducedPom>true</createDependencyReducedPom>
                    <transformers>
                        <transformer
                            implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
                        <transformer
                            implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                            <mainClass>${mainClass}</mainClass>
                        </transformer>
                    </transformers>
                    <!-- exclude signed Manifests -->
                    <filters>
                        <filter>
                            <artifact>*:*</artifact>
                            <excludes>
                                <exclude>META-INF/*.SF</exclude>
                                <exclude>META-INF/*.DSA</exclude>
                                <exclude>META-INF/*.RSA</exclude>
                            </excludes>
                        </filter>
                    </filters>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>${mainClass}</mainClass>
                            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

测试应用程序.java

package test;

import io.dropwizard.Application;
import io.dropwizard.forms.MultiPartBundle;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;

public class TestApp extends Application<TestConf> {

    public static void main(String[] args){
        try {
            new TestApp().run(args);
        }
        catch(Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public String getName() {
        return "ID Generator Server";
    }

    @Override
    public void initialize(final Bootstrap<TestConf> bootstrap) {
        bootstrap.addBundle(new MultiPartBundle());
    }

    @Override
    public void run(final TestConf configuration,
                    final Environment environment) {
        final TestRes resource = new TestRes(
                configuration.getTemplate(),
                configuration.getDefaultName()
            );
            environment.jersey().register(resource);
    }

}

testconf.java文件

package test;

import io.dropwizard.Configuration;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.hibernate.validator.constraints.*;

public class TestConf extends Configuration {

    @NotEmpty
    private String template;

    @NotEmpty
    private String defaultName = "MarineTraffic";

    @JsonProperty
    public String getTemplate() {
        return template;
    }

    @JsonProperty
    public void setTemplate(String template) {
        this.template = template;
    }

    @JsonProperty
    public String getDefaultName() {
        return defaultName;
    }

    @JsonProperty
    public void setDefaultName(String name) {
        this.defaultName = name;
    }
}

测试资源.java

package test;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Path("/hive")
public class TestRes {

    protected final static Logger LOGGER = LoggerFactory.getLogger(TestRes.class);
    protected final static String HEADER = "GroupService::";

    public TestRes(String template, String defaultName) {
        LOGGER.info(HEADER + "init: PostConstruct");
    }

    @GET
    @Path("/test")
    @Produces(MediaType.TEXT_PLAIN)
    public String getNewID() {

        return "works";
    }
}

我得到的错误是:

WARN  [2017-08-10 21:50:21,444] org.glassfish.jersey.internal.Errors: The following warnings have been detected: WARNING: Unknown HK2 failure detected:
MultiException stack 1 of 2
java.lang.NullPointerException
    at com.sun.jersey.core.provider.jaxb.AbstractJAXBProvider.setConfiguration(AbstractJAXBProvider.java:107)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
...
    at test.TestApp.main(TestApp.java:12)
MultiException stack 2 of 2
java.lang.IllegalStateException: Unable to perform operation: method inject on com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$App
    at org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:392)
    at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:471)
...

WARNING: Unknown HK2 failure detected:
MultiException stack 1 of 3
java.lang.NullPointerException
    at com.sun.jersey.core.provider.jaxb.AbstractJAXBProvider.setConfiguration(AbstractJAXBProvider.java:107)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
...
    at test.TestApp.main(TestApp.java:12)
MultiException stack 2 of 3
java.lang.IllegalStateException: Unable to perform operation: method inject on com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$App
    at org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:392)
    at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:471)
...
    at test.TestApp.main(TestApp.java:12)
MultiException stack 3 of 3
java.lang.IllegalStateException: Unable to perform operation: create on org.glassfish.jersey.message.internal.MessageBodyFactory
    at org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:386)
    at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:471)
...

我发现有些用户也遇到了类似的错误(比如dropwizard和hive/hiverunner与maven和http://thread.gmane.org/gmane.comp.java.dropwizard.devel/461)
这(在泽西岛的不兼容性)是导致错误的问题吗?有人知道怎么解决吗?

rks48beu

rks48beu1#

是的,它的jersey冲突问题将jersey 1依赖项(com.sun.jersey)从hivejdbc和hadoop核心中排除。已经运行了你的测试应用程序,它与以下排除工作。

<dependency>
        <groupId>org.apache.hive</groupId>
        <artifactId>hive-jdbc</artifactId>
        <version>1.1.0</version>
        <exclusions>
            <exclusion>
                <groupId>com.sun.jersey</groupId>
                <artifactId>*</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.apache.hadoop</groupId>
        <artifactId>hadoop-core</artifactId>
        <version>1.2.1</version>
        <exclusions>
            <exclusion>
                <groupId>com.sun.jersey</groupId>
                <artifactId>*</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

相关问题