2012-11-06 63 views
0

我想設置一個Spring應用程序在eclipse中第一次運行。我正在運行它作爲一個獨立的Java應用程序。該應用程序構建沒有任何錯誤,但是當我去執行它,我得到以下堆棧跟蹤一個ClassNotFoundException:在Eclipse中彈簧類路徑問題

DataLoadService [Java Application] 
    com.pikefin.services.DataLoadService at localhost:52871 
     Thread [main] (Suspended (exception ClassNotFoundException))  
      URLClassLoader$1.run() line: 217  
      AccessController.doPrivileged(PrivilegedExceptionAction<T>, AccessControlContext) line: not available [native method] 
      Launcher$AppClassLoader(URLClassLoader).findClass(String) line: 205 
      Launcher$AppClassLoader(ClassLoader).loadClass(String, boolean) line: 321 
      Launcher$AppClassLoader.loadClass(String, boolean) line: 294  
      Launcher$AppClassLoader(ClassLoader).loadClass(String) line: 266  
      ClassPathXmlApplicationContext(AbstractApplicationContext).<init>(ApplicationContext) line: 161 
      ClassPathXmlApplicationContext(AbstractRefreshableApplicationContext).<init>(ApplicationContext) line: 90 
      ClassPathXmlApplicationContext(AbstractRefreshableConfigApplicationContext).<init>(ApplicationContext) line: 59 
      ClassPathXmlApplicationContext(AbstractXmlApplicationContext).<init>(ApplicationContext) line: 61 
      ClassPathXmlApplicationContext.<init>(String[], boolean, ApplicationContext) line: 136 
      ClassPathXmlApplicationContext.<init>(String) line: 83 
      DataLoadService.main(String[]) line: 20 
    /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/bin/java (Nov 6, 2012 1:14:23 PM) 

它發生在這行代碼:

ApplicationContext context=new ClassPathXmlApplicationContext("classpath:spring.xml"); 

spring.xml得到在構建過程中移到類/文件夾中,所以我嘗試將類文件夾添加到啓動配置中(請參見截圖)。

enter image description here

我與Eclipse 3.7.2和3.1.1春季

+0

你寫'ClassDefNotFound',但你的粘貼顯示'ClassNotFoundException'? –

+0

Correcte。謝謝 – opike

回答

0

工作檢查彈簧庫。這個問題是關於項目構建路徑和配置。

0

我不知道spring但下面是可疑:

ApplicationContext context=new ClassPathXmlApplicationContext("classpath:spring.xml"); 

也許這應該是

ApplicationContext context=new ClassPathXmlApplicationContext("spring.xml"); 

例如,在this question使用是

ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); 

除非您的文件實際上被稱爲classpath:spring.xml,而不是sprint.xml,但我懷疑這一點。

+0

我試着刪除類路徑:前綴,但仍然得到相同的錯誤。 – opike