我正在研究使用jclouds作为Rackspace Cloud Files的druid扩展程序,我遇到了Google guice的问题,而且我对Java不太自信。
我已经看过this question,但似乎guice版本中没有冲突。
这是正在执行的代码:
@Provides
@LazySingleton
public CloudFilesApi getCloudFilesApi(final CloudFilesAccountConfig config) {
log.info("Provider: " + config.getProvider());
log.info("Username: " + config.getUserName());
log.info("Api key: " + config.getApiKey());
ContextBuilder cb = ContextBuilder.newBuilder(config.getProvider());
log.info("Context builder built.");
cb = cb.credentials(config.getUserName(), config.getApiKey());
log.info("Context builder authenticated.");
CloudFilesApi cfa = cb.buildApi(CloudFilesApi.class);
log.info("Cloud Files Api built.");
return cfa;
}
这是日志:
2015-08-26T13:15:53,663 INFO [main] io.druid.guice.JsonConfigurator - Loaded class[class io.druid.storage.cloudfiles.CloudFilesAccountConfig] from props[druid.cloudfiles.] as [io.druid.storage.cloudfiles.CloudFilesAccountConfig@32d70ac]
2015-08-26T13:15:53,664 INFO [main] io.druid.storage.cloudfiles.CloudFilesStorageDruidModule - Provider: rackspace-cloudfiles-us
2015-08-26T13:15:53,664 INFO [main] io.druid.storage.cloudfiles.CloudFilesStorageDruidModule - Username: <value>
2015-08-26T13:15:53,665 INFO [main] io.druid.storage.cloudfiles.CloudFilesStorageDruidModule - Api key: <value>
2015-08-26T13:15:54,425 INFO [main] io.druid.storage.cloudfiles.CloudFilesStorageDruidModule - Context builder built.
2015-08-26T13:15:54,425 INFO [main] io.druid.storage.cloudfiles.CloudFilesStorageDruidModule - Context builder authenticated.
Exception in thread "main" com.google.inject.CreationException: Guice creation errors:
1) Error injecting constructor, java.lang.NoClassDefFoundError: com/google/inject/internal/util/$Preconditions
at io.druid.guice.FireDepartmentsProvider.<init>(FireDepartmentsProvider.java:41)
while locating io.druid.guice.FireDepartmentsProvider
at io.druid.guice.RealtimeModule.configure(RealtimeModule.java:79)
while locating java.util.List<io.druid.segment.realtime.FireDepartment>
for parameter 0 at io.druid.segment.realtime.RealtimeMetricsMonitor.<init>(RealtimeMetricsMonitor.java:42)
while locating io.druid.segment.realtime.RealtimeMetricsMonitor
at io.druid.server.metrics.MetricsModule.getMonitorScheduler(MetricsModule.java:78)
at io.druid.server.metrics.MetricsModule.getMonitorScheduler(MetricsModule.java:78)
while locating com.metamx.metrics.MonitorScheduler
at io.druid.server.metrics.MetricsModule.configure(MetricsModule.java:63)
while locating com.metamx.metrics.MonitorScheduler annotated with @com.google.inject.name.Named(value=ForTheEagerness)
1 error
at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:448)
at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:184)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:110)
at com.google.inject.Guice.createInjector(Guice.java:96)
at com.google.inject.Guice.createInjector(Guice.java:73)
at com.google.inject.Guice.createInjector(Guice.java:62)
at io.druid.initialization.Initialization.makeInjectorWithModules(Initialization.java:412)
at io.druid.cli.GuiceRunnable.makeInjector(GuiceRunnable.java:55)
at io.druid.cli.ServerRunnable.run(ServerRunnable.java:37)
at io.druid.cli.Main.main(Main.java:91)
Caused by: java.lang.NoClassDefFoundError: com/google/inject/internal/util/$Preconditions
at org.nnsoft.guice.rocoto.configuration.ConfigurationModule.configure(ConfigurationModule.java:64)
at com.google.inject.AbstractModule.configure(AbstractModule.java:62)
at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:230)
at com.google.inject.spi.Elements.getElements(Elements.java:103)
at com.google.inject.spi.Elements.getElements(Elements.java:94)
at org.nnsoft.guice.rocoto.Rocoto.expandVariables(Rocoto.java:52)
at org.nnsoft.guice.rocoto.Rocoto.expandVariables(Rocoto.java:47)
at org.jclouds.config.BindPropertiesToExpandedValues.configure(BindPropertiesToExpandedValues.java:45)
at com.google.inject.AbstractModule.configure(AbstractModule.java:62)
at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:230)
at com.google.inject.spi.Elements.getElements(Elements.java:103)
at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:136)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:104)
at com.google.inject.Guice.createInjector(Guice.java:96)
at com.google.inject.Guice.createInjector(Guice.java:84)
at org.jclouds.ContextBuilder.expandProperties(ContextBuilder.java:382)
at org.jclouds.ContextBuilder.buildInjector(ContextBuilder.java:317)
at org.jclouds.ContextBuilder.buildApi(ContextBuilder.java:644)
at org.jclouds.ContextBuilder.buildApi(ContextBuilder.java:636)
at io.druid.storage.cloudfiles.CloudFilesStorageDruidModule.getCloudFilesApi(CloudFilesStorageDruidModule.java:68)
[...]
我也不明白为什么没有打印字符串"Cloud Files Api built."
。
classpath 是lib
目录:
user@host:/opt/druid# ls lib | grep guice
guice-4.0-beta.jar
guice-assistedinject-3.0.jar
guice-multibindings-4.0-beta.jar
guice-servlet-4.0-beta.jar
jersey-guice-1.17.1.jar
更新1
也许与this issue有关?我要尝试降级到Google guice 3.0。
更新2
我将Google guice降级为3.0,现在我已经:
user@host:/opt/druid# ls lib | grep guice
guice-3.0.jar
guice-assistedinject-3.0.jar
guice-multibindings-3.0.jar
guice-servlet-3.0.jar
jersey-guice-1.17.1.jar
现在错误发生了变化:
2015-08-26T14:22:06,978 INFO [main] io.druid.guice.JsonConfigurator - Loaded class[class io.druid.storage.cloudfiles.CloudFilesAccountConfig] from props[druid.cloudfiles.] as [io.druid.storage.cloudfiles.CloudFilesAccountConfig@273f1cb3]
2015-08-26T14:22:06,979 INFO [main] io.druid.storage.cloudfiles.CloudFilesStorageDruidModule - Provider: rackspace-cloudfiles-us
2015-08-26T14:22:06,980 INFO [main] io.druid.storage.cloudfiles.CloudFilesStorageDruidModule - Username: viralizecloud
2015-08-26T14:22:06,980 INFO [main] io.druid.storage.cloudfiles.CloudFilesStorageDruidModule - Api key: df185fe598ed99ef27a247a21b578c3a
2015-08-26T14:22:07,782 INFO [main] io.druid.storage.cloudfiles.CloudFilesStorageDruidModule - Context builder built.
2015-08-26T14:22:07,783 INFO [main] io.druid.storage.cloudfiles.CloudFilesStorageDruidModule - Context builder authenticated.
Exception in thread "main" com.google.inject.CreationException: Guice creation errors:
1) Error injecting constructor, java.lang.VerifyError: Cannot inherit from final class
at io.druid.guice.FireDepartmentsProvider.<init>(FireDepartmentsProvider.java:41)
while locating io.druid.guice.FireDepartmentsProvider
at io.druid.guice.RealtimeModule.configure(RealtimeModule.java:79)
while locating java.util.List<io.druid.segment.realtime.FireDepartment>
for parameter 0 at io.druid.segment.realtime.RealtimeMetricsMonitor.<init>(RealtimeMetricsMonitor.java:42)
while locating io.druid.segment.realtime.RealtimeMetricsMonitor
at io.druid.server.metrics.MetricsModule.getMonitorScheduler(MetricsModule.java:78)
at io.druid.server.metrics.MetricsModule.getMonitorScheduler(MetricsModule.java:78)
while locating com.metamx.metrics.MonitorScheduler
at io.druid.server.metrics.MetricsModule.configure(MetricsModule.java:63)
while locating com.metamx.metrics.MonitorScheduler annotated with @com.google.inject.name.Named(value=ForTheEagerness)
1 error
at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:435)
at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:183)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:109)
at com.google.inject.Guice.createInjector(Guice.java:95)
at com.google.inject.Guice.createInjector(Guice.java:72)
at com.google.inject.Guice.createInjector(Guice.java:62)
at io.druid.initialization.Initialization.makeInjectorWithModules(Initialization.java:412)
at io.druid.cli.GuiceRunnable.makeInjector(GuiceRunnable.java:55)
at io.druid.cli.ServerRunnable.run(ServerRunnable.java:37)
at io.druid.cli.Main.main(Main.java:91)
Caused by: java.lang.VerifyError: Cannot inherit from final class
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2595)
at java.lang.Class.getDeclaredConstructors(Class.java:1914)
at com.google.inject.spi.InjectionPoint.forConstructorOf(InjectionPoint.java:243)
at com.google.inject.internal.ConstructorBindingImpl.create(ConstructorBindingImpl.java:96)
at com.google.inject.internal.InjectorImpl.createUninitializedBinding(InjectorImpl.java:629)
at com.google.inject.internal.InjectorImpl.createJustInTimeBinding(InjectorImpl.java:845)
at com.google.inject.internal.InjectorImpl.createJustInTimeBindingRecursive(InjectorImpl.java:772)
at com.google.inject.internal.InjectorImpl.getJustInTimeBinding(InjectorImpl.java:256)
at com.google.inject.internal.InjectorImpl.getBindingOrThrow(InjectorImpl.java:205)
at com.google.inject.internal.InjectorImpl.getInternalFactory(InjectorImpl.java:853)
at com.google.inject.internal.FactoryProxy.notify(FactoryProxy.java:46)
at com.google.inject.internal.ProcessedBindingData.runCreationListeners(ProcessedBindingData.java:50)
at com.google.inject.internal.InternalInjectorCreator.initializeStatically(InternalInjectorCreator.java:133)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:106)
at com.google.inject.Guice.createInjector(Guice.java:95)
at org.jclouds.ContextBuilder.buildInjector(ContextBuilder.java:402)
at org.jclouds.ContextBuilder.buildInjector(ContextBuilder.java:326)
at org.jclouds.ContextBuilder.buildApi(ContextBuilder.java:644)
at org.jclouds.ContextBuilder.buildApi(ContextBuilder.java:636)
at io.druid.storage.cloudfiles.CloudFilesStorageDruidModule.getCloudFilesApi(CloudFilesStorageDruidModule.java:68)
[...]
答案 0 :(得分:2)
查看你的类路径:
static class ToSort {
Integer val;
public ToSort(Integer val) {
this.val = val;
}
@Override
public String toString() {
return "ToSort{" +
"val=" + val +
'}';
}
}
public static void main(String[] args) {
Observable.just(new ToSort(1), new ToSort(2), new ToSort(3))
.toSortedList((o1, o2) -> (-1) * o1.val.compareTo(o2.val))
.subscribe(list -> System.out.print(Arrays.toString(list.toArray())));
}
您正在使用Guice v4.0b但是使用了AssistedInject Guice扩展程序的v3.0。您应该从版本到版本一次升级它们。听起来你把所有东西都放回到v3.0,这有效,但你可以改为升级AssistedInject扩展。