简体   繁体   English

Eclipse中的Spring Classpath问题

[英]Spring classpath issue in eclipse

I'm trying to set up a Spring application to run in eclipse for the first time. 我正在尝试设置一个Spring应用程序以使其首次在Eclipse中运行。 I'm running it at as a standalone java application. 我将其作为独立的Java应用程序运行。 The app builds without any errors but when I go to execute it, I get a ClassNotFoundException with the following stack trace: 该应用程序构建没有任何错误,但是当我去执行它,我得到以下堆栈跟踪一个ClassNotFoundException:

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)

It's happening on this line of code: 这是在以下代码行上发生的:

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

spring.xml gets moved into the class/ folder during the build process so I tried adding the class folder to the launch configuration (see screenshot). spring.xml在构建过程中移至class /文件夹中,因此我尝试将class文件夹添加到启动配置中(请参见屏幕截图)。

在此处输入图片说明

I'm working with eclipse 3.7.2 and spring 3.1.1 我正在使用Eclipse 3.7.2和Spring 3.1.1

Check the spring libs. 检查弹簧库。 This issue is about the project build path and configuration. 此问题与项目构建路径和配置有关。

I don't know spring but the following is suspicious: 我不知道spring但以下情况令人怀疑:

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

Perhaps it should be 也许应该是

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

For example, in this question the usage is 例如,在这个问题中 ,用法是

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

Unless your file is actually called classpath:spring.xml , not sprint.xml , but I doubt that. 除非您的文件实际上叫做classpath:spring.xml ,而不是sprint.xml ,但是我对此表示怀疑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM