2015-04-30 102 views
0

我想在我的IntelliJ項目中使用類TitanGraph。因此,我在我的項目中包含了所有必要的庫。該項目編譯得很好,但只要Spring試圖用這個類類型創建一個bean,它就會拋出一個ClassNotFoundException異常。 我的豆:創建Bean時發生Spring ClassNotFoundException

public class GraphEngineGlue { 
    @Bean 
    public TitanGraph titanGraph() { 
     return TitanFactory.open(configuration); 
    } 
} 

在我的XML文件,我有以下幾點參考:

<bean class="my.package.GraphEngineGlue"/> 

我在做什麼錯?運行時是否可能包含某些庫?

編輯:

堆棧跟蹤

3664 [main  ] ERROR com.mypackage.web.spring.BootstrapAwareContextLoaderListener - Unexpected error during initialization, cause: java.lang.ClassNotFoundException: com.thinkaurelius.titan.core.TitanGraph 
java.lang.IllegalStateException: Cannot load configuration class: com.mypackage.GraphEngineGlue 
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:368) 
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:244) 
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) 
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:633) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:461) 
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:410) 
    at com.mypackage 
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) 
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112) 
    at com.mypackage 
    at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:782) 
    at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:424) 
    at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:774) 
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:249) 
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1242) 
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:717) 
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:494) 
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64) 
    at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:229) 
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:172) 
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64) 
    at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:229) 
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64) 
    at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95) 
    at org.eclipse.jetty.server.Server.doStart(Server.java:282) 
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64) 
    at com.mypackage 
    at com.mypackage 
    at com.mypackage 
    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:483) 
    at com.mypackage.Main(Main.java:10) 
    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:483) 
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140) 
Caused by: java.lang.NoClassDefFoundError: com/thinkaurelius/titan/core/TitanGraph 
    at java.lang.Class.getDeclaredMethods0(Native Method) 
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2693) 
    at java.lang.Class.getDeclaredMethods(Class.java:1967) 
    at org.springframework.cglib.core.ReflectUtils.addAllMethods(ReflectUtils.java:348) 
    at org.springframework.cglib.proxy.Enhancer.getMethods(Enhancer.java:421) 
    at org.springframework.cglib.proxy.Enhancer.generateClass(Enhancer.java:456) 
    at org.springframework.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25) 
    at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216) 
    at org.springframework.cglib.proxy.Enhancer.createHelper(Enhancer.java:377) 
    at org.springframework.cglib.proxy.Enhancer.createClass(Enhancer.java:317) 
    at org.springframework.context.annotation.ConfigurationClassEnhancer.createClass(ConfigurationClassEnhancer.java:125) 
    at org.springframework.context.annotation.ConfigurationClassEnhancer.enhance(ConfigurationClassEnhancer.java:98) 
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:358) 
    ... 39 more 
Caused by: java.lang.ClassNotFoundException: com.thinkaurelius.titan.core.TitanGraph 
    at java.net.URLClassLoader$1.run(URLClassLoader.java:372) 
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357) 
    ... 52 more 
+1

請添加堆棧跟蹤 – Jens

+0

還應該將它們添加到部署程序集 –

+0

我添加了堆棧跟蹤。通過項目設置 - >模塊 - > MyModule - >依賴關係 - > + - >選擇瓶子 - >應用 – Casper

回答

1

1)我不認爲這是原因,但如果你在一個Java配置定義bean爲你做,那麼你就不需要定義它也是一個基於xml的配置。

2)檢查你是否在正確的範圍內包含了依賴項,我不知道你是否使用maven或ivy或whatnot,但是如果依賴項設置爲僅用於測試例如,你運行應用程序作爲一種主要的方法,而不是在測試環境中,那麼你將不會有可用的類。

+0

添加了所有庫。我的依賴關係未包含在類路徑中,因爲依賴關係的文件夾不是。 – Casper

+0

那麼它解決了嗎?那麼你應該回答你的問題:) –