简体   繁体   English

Dropwizard和hive-jdbc之间不兼容

[英]Incompatibility between Dropwizard and hive-jdbc

I'm trying to create a WS REST using Dropwizard for getting a Hive result of a query and presenting in XML format. 我正在尝试使用Dropwizard创建WS REST,以获取查询的Hive结果并以XML格式呈现。 Each separated part of this could be done without error. 每个单独的部分都可以正确执行。

When I joined everything I reach a incompatibility between Dropwizard and hive-jdbc. 当我加入所有内容时,我在Dropwizard和hive-jdbc之间达到了不兼容的状态。 Apparently hive-jdbc has jersey 1 as dependency and Dropwizard has jersey 2. 显然,hive-jdbc具有球衣1作为依赖项,而Dropwizard具有球衣2。

I'm not sure if this is the problem. 我不确定这是否是问题。 I'd tried to exclude dependency in pom.xml, but didn't solve. 我试图排除pom.xml中的依赖关系,但没有解决。

I tried to make an application just putting hive-jdbc as dependency in pom.xml file without using or importing in any part of the code, and the error still happening. 我试图制作一个仅将hive-jdbc作为依赖项放入pom.xml文件的应用程序,而没有使用或导入代码的任何部分,并且该错误仍然发生。

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>

TestApp.java TestApp.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 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;
    }
}

TestRes.java TestRes.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";
    }
}

The error I got was like: 我得到的错误是:

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)
...

I found that some users are getting similar error (as dropwizard and hive/hiverunner integration with maven and http://thread.gmane.org/gmane.comp.java.dropwizard.devel/461 ) 我发现有些用户遇到类似的错误(例如dropwizard和与Mavenhttp://thread.gmane.org/gmane.comp.java.dropwizard.devel/461的 hive / hiverunner集成

Is this (incompatibility in Jersey) the problem that is causing the error? 这是导致错误的问题(泽西岛不兼容)吗? Does anyone knows how to solve it? 有人知道如何解决吗?

Yup, its jersey conflict issue, exclude jersey 1 dependencies (com.sun.jersey) from both hive-jdbc and hadoop-core. Yup,它的球衣冲突问题,从hive-jdbc和hadoop-core中都排除了球衣1依赖项(com.sun.jersey)。 Had ran your test application and it worked with below exclusions. 已经运行了您的测试应用程序,并且可以使用以下排除项。

 <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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM