Dropwizard应用程序由AbstractJAXBProvider崩溃

时间:2015-12-07 15:08:25

标签: java jersey mahout dropwizard mahout-recommender

我使用Dropwizard和Gradle作为构建系统实现了服务器应用程序。现在我想整合Apache Mahout以进行一些推荐系统操作。

添加Mahout依赖项并尝试运行后,我得到例外。

我的初始依赖关系看起来像

dependencies {
    compile 'io.dropwizard:dropwizard-core:0.9.1'
    compile 'io.dropwizard:dropwizard-jdbi:0.9.1'
    compile 'mysql:mysql-connector-java:5.1.37'
    compile 'redis.clients:jedis:2.8.0'
    compile 'com.google.guava:guava:18.0'
    compile 'joda-time:joda-time:2.9.1'
    compile 'org.apache.commons:commons-math3:3.4.1'
}

为了做一些基本的推荐系统,我整合了依赖

compile 'org.apache.mahout:mahout-mr:0.11.1'

当我现在运行应用程序时,我得到一个NoClassDefFoundException:

WARN  [2015-12-07 15:03:09,696] org.glassfish.jersey.internal.Errors: 
The following warnings have been detected: WARNING: HK2 service reification 
failed for [com.sun.jersey.core.impl.provider.entity.MimeMultipartProvider] 
with an exception:
MultiException stack 1 of 2
java.lang.NoClassDefFoundError: javax/mail/internet/ParseException

所以我尝试通过

将这些内容整合为额外的依赖
compile 'com.sun.mail:javax.mail:1.5.4'

再次运行应用程序,我得到一个不同的例外:

WARN  [2015-12-07 15:05:02,161] 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:109)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)

导致例外的代码来自泽西岛:

@Context
public void setConfiguration(FeaturesAndProperties fp) {
    formattedOutput = fp.getFeature(FeaturesAndProperties.FEATURE_FORMATTED); // << Crash here
    xmlRootElementProcessing = fp.getFeature(FeaturesAndProperties.FEATURE_XMLROOTELEMENT_PROCESSING);
}

所以看起来这个功能在这里是空的,我们无法对它做任何事情。任何人都知道发生了什么,或者我如何管理它?

2 个答案:

答案 0 :(得分:1)

问题在于Dropwizard是否带有Jersey依赖(在我的情况下是2.22.x中的org.glassfish.jersey),Apache Mahout附带了不同的Jersey依赖(在我的情况下,com.sun.jersey在1.9中) )。

因此排除Mahout Jersey的依赖性。在我的情况下,这是由

完成的
 @Override
protected void onHandleIntent(Intent intent) {
    Log.e(TAG, "onHandleIntent");
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    boolean sent = sharedPreferences.getBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, false);
    if (sent) {
        return;
    }

    try {
        // [START register_for_gcm]
        // Initially this call goes out to the network to retrieve the token, subsequent calls
        // are local.
        // R.string.gcm_defaultSenderId (the Sender ID) is typically derived from google-services.json.
        // See https://developers.google.com/cloud-messaging/android/start for details on this file.
        // [START get_token]
        InstanceID instanceID = InstanceID.getInstance(this);
        String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId),
                GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
        // [END get_token]
        Log.e(TAG, "GCM Registration Token: " + token);

        sendRegistrationToServer(token);

        // Subscribe to topic channels
        subscribeTopics(token);

        // You should store a boolean that indicates whether the generated token has been
        // sent to your server. If the boolean is false, send the token to your server,
        // otherwise your server should have already received the token.
        sharedPreferences.edit().putBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, true).apply();
        // [END register_for_gcm]
    } catch (Exception e) {
        Log.e(TAG, "Failed to complete token refresh", e);
        // If an exception happens while fetching the new token or updating our registration data
        // on a third-party server, this ensures that we'll attempt the update at a later time.
        sharedPreferences.edit().putBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, false).apply();
    }
    // Notify UI that registration has completed, so the progress indicator can be hidden.
    Intent registrationComplete = new Intent(QuickstartPreferences.REGISTRATION_COMPLETE);
    LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete);
    Log.e(TAG, "end of intent");
}

答案 1 :(得分:0)

您使用的依赖项很可能具有与您的模块不兼容的依赖项。

如果您使用的是maven,请使用mvn dependency:tree来确定。