本文介绍了Google Guice找不到课程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当时正在使用Google Guice编写程序,但出现异常!为了测试,我写了一个小程序,但是它也没有用!

I was writing program using Google Guice, but I got exception! For testing I wrote a small program, but it didn't work too!

所有类:

主要.java:

import com.google.inject.Guice;

public class Main {
    public static void main(String[] args) {
        ITest test = Guice.createInjector(new TestModule()).getInstance(ITest.class);
    }
}

ITest.java:

public interface ITest {
}

Test.java:

public class Test implements ITest {
}

TestModule.java:

import com.google.inject.AbstractModule;

public class TestModule extends AbstractModule {
    @Override
    protected void configure() {
        bind(ITest.class).to(Test.class);
    }
}






pom.xml 中的依赖项:

    <dependency>
        <groupId>com.google.inject</groupId>
        <artifactId>guice</artifactId>
        <version>4.0</version>
    </dependency>






异常堆栈跟踪:


Exception stack trace:

"C:\Program Files\Java\jdk1.8.0_101\bin\java" -Didea.launcher.port=7532 "-Didea.launcher.bin.path=D:\Rostislav\IDEs\IntelliJ IDEA Community Edition 2016.2.2\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_101\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\access-bridge.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\rt.jar;D:\Rostislav\Projects\OSLoader\OSLoaderServer\target\classes;C:\Documents and Settings\Администратор\.m2\repository\org\xerial\sqlite-jdbc\3.8.11.2\sqlite-jdbc-3.8.11.2.jar;C:\Documents and Settings\Администратор\.m2\repository\com\netflix\rxjava\rxjava-core\0.20.7\rxjava-core-0.20.7.jar;C:\Documents and Settings\Администратор\.m2\repository\org\jboss\weld\weld-core\1.1.4.Final\weld-core-1.1.4.Final.jar;C:\Documents and Settings\Администратор\.m2\repository\javax\enterprise\cdi-api\1.0-SP4\cdi-api-1.0-SP4.jar;C:\Documents and Settings\Администратор\.m2\repository\org\jboss\weld\weld-api\1.1.Final\weld-api-1.1.Final.jar;C:\Documents and Settings\Администратор\.m2\repository\org\jboss\weld\weld-spi\1.1.Final\weld-spi-1.1.Final.jar;C:\Documents and Settings\Администратор\.m2\repository\javax\annotation\jsr250-api\1.0\jsr250-api-1.0.jar;C:\Documents and Settings\Администратор\.m2\repository\org\javassist\javassist\3.14.0-GA\javassist-3.14.0-GA.jar;C:\Documents and Settings\Администратор\.m2\repository\com\google\guava\guava\r06\guava-r06.jar;C:\Documents and Settings\Администратор\.m2\repository\org\jboss\spec\javax\interceptor\jboss-interceptors-api_1.1_spec\1.0.0.Beta1\jboss-interceptors-api_1.1_spec-1.0.0.Beta1.jar;C:\Documents and Settings\Администратор\.m2\repository\org\jboss\interceptor\jboss-interceptor-spi\2.0.0.CR1\jboss-interceptor-spi-2.0.0.CR1.jar;C:\Documents and Settings\Администратор\.m2\repository\org\jboss\interceptor\jboss-interceptor-core\2.0.0.CR1\jboss-interceptor-core-2.0.0.CR1.jar;C:\Documents and Settings\Администратор\.m2\repository\org\slf4j\slf4j-ext\1.5.10\slf4j-ext-1.5.10.jar;C:\Documents and Settings\Администратор\.m2\repository\ch\qos\cal10n\cal10n-api\0.7.2\cal10n-api-0.7.2.jar;C:\Documents and Settings\Администратор\.m2\repository\org\slf4j\slf4j-api\1.5.10\slf4j-api-1.5.10.jar;C:\Documents and Settings\Администратор\.m2\repository\org\jboss\weld\weld-build-config\1.1.4.Final\weld-build-config-1.1.4.Final.jar;C:\Documents and Settings\Администратор\.m2\repository\org\json\json\20160212\json-20160212.jar;C:\Documents and Settings\Администратор\.m2\repository\com\google\inject\guice\4.0\guice-4.0.jar;C:\Documents and Settings\Администратор\.m2\repository\javax\inject\javax.inject\1\javax.inject-1.jar;C:\Documents and Settings\Администратор\.m2\repository\aopalliance\aopalliance\1.0\aopalliance-1.0.jar;C:\Documents and Settings\Администратор\.m2\repository\com\j256\ormlite\ormlite-core\4.47\ormlite-core-4.47.jar;C:\Documents and Settings\Администратор\.m2\repository\com\j256\ormlite\ormlite-jdbc\4.47\ormlite-jdbc-4.47.jar;C:\Documents and Settings\Администратор\.m2\repository\javax\servlet\javax.servlet-api\3.1.0\javax.servlet-api-3.1.0.jar;D:\Rostislav\IDEs\IntelliJ IDEA Community Edition 2016.2.2\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain com.dugin.rostislav.image.Main
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/cache/RemovalListener
    at com.google.inject.internal.InheritingState.<init>(InheritingState.java:67)
    at com.google.inject.internal.InjectorShell$Builder.getState(InjectorShell.java:209)
    at com.google.inject.internal.InjectorShell$Builder.lock(InjectorShell.java:115)
    at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:103)
    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 com.dugin.rostislav.image.Main.main(Main.java:8)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.lang.ClassNotFoundException: com.google.common.cache.RemovalListener
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 13 more
Picked up _JAVA_OPTIONS: -Xmx512M

Process finished with exit code 1






为什么会出现异常以及如何解决?


Why did I get exception and how to fix it?

推荐答案

检查您的依赖项。

您有 C:\文档和设置\Администратор\.m2\存储库\com\google\guava\guava\r06\guava-r06.jar 程序启动期间的类​​路径。

You have C:\Documents and Settings\Администратор\.m2\repository\com\google\guava\guava\r06\guava-r06.jar in your classpath during program startup.

只有一个依赖项的简单本地程序

A simple local program with only one dependency

<dependencies>
    <dependency>
        <groupId>com.google.inject</groupId>
        <artifactId>guice</artifactId>
        <version>4.0</version>
    </dependency>
</dependencies>

向我显示〜\.m2\repository\com\ \google\guava\guava\16.0.1\guava-16.0.1.jar; ,程序运行正常。

shows to me ~\.m2\repository\com\google\guava\guava\16.0.1\guava-16.0.1.jar; and the program works fine.

这篇关于Google Guice找不到课程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 05:17