为什么我无法运行Spring程序?

时间:2013-11-24 13:24:26

标签: eclipse spring spring-mvc

当我试图在eclipse中运行spring程序时,我得到以下错误。

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
    BeanFactory cannot be resolved to a type
    XmlBeanFactory cannot be resolved to a type
    FileSystemResource cannot be resolved to a type
    triangle cannot be resolved

    at Org.koushik.javabrains.DrawingApp.main(DrawingApp.java:8)

我试图解决此错误。我也下载spring.jar文件并把它放在classpath.But,我仍然得到错误。我也想要整个spring.jar应该包括 所有spring.jar文件。

请帮助我,并提前致谢。

2 个答案:

答案 0 :(得分:1)

要管理您的依赖项,请使用MavenGradleAnt + Ivy等工具。这些将使您的生活变得更加轻松,依赖关系将得到管理,您将获得所有传递依赖项(您使用的框架所依赖的依赖项)。这将为您节省大量的互联网搜索。

使用这些工具中的任何一个,您都可以创建一个构建文件(ant和maven使用XML,Gralde使用Groovy)并表达您的依赖关系。

例如,这个用于gradle的构建文件,build.gradle将创建一个jar并使用所有依赖项。

apply plugin: 'java'

repositories {
    mavenCentral()
}

dependencies {
    compile group: 'org.springframework', name: 'spring-context', version: '3.2.5.RELEASE'        
    compile group: 'org.springframework', name: 'spring-context-support', version: '3.2.5.RELEASE'        
    testCompile group: 'junit', name: 'junit', version: '4.+'
}

这个gradle.build将添加所需的spring jar及其所需的依赖项。

答案 1 :(得分:0)

您收到该异常是因为您没有正确的jar文件。

您需要这些罐子用于基于Spring IOC / DI模块的项目。 您可以从here

下载广告罐

学习并开始使用像Deinum这样的依赖管理工具

enter image description here