从Spring Tool Suite 3.6.4开始我正在尝试开发一个Spring项目,我已经做了很多事情,例如添加STS lib文件夹中的jar和apache common-logging 1.1.3和1.2。
STS在主要课程中显示错误 新的ClassPathXmlApplicationContext(“Beans.xml”);
当我试图解决它时,STS显示配置BuildPath我通过观看Youtube中的教程添加了所有的jar。
我使用的是JAVA 1.6版本,OS Ubuntu,STS 3.6.4 下面列出的jar已添加到buildpath
/home/axxera/sts-bundle/pivotal-tc-server-developer-3.1.0.RELEASE/lib/aws-java-sdk-1.7.5.jar
/home/axxera/sts-bundle/pivotal-tc-server-developer-3.1.0.RELEASE/lib/com.springsource.org.apache.commons.beanutils-1.8.3.jar
/home/axxera/sts-bundle/pivotal-tc-server-developer-3.1.0.RELEASE/lib/com.springsource.org.apache.commons.cli-1.2.0.jar
/home/axxera/sts-bundle/pivotal-tc-server-developer-3.1.0.RELEASE/lib/com.springsource.org.apache.commons.codec-1.5.0.jar
/home/axxera/sts-bundle/pivotal-tc-server-developer-3.1.0.RELEASE/lib/com.springsource.org.apache.commons.collections-3.2.1.jar
/home/axxera/sts-bundle/pivotal-tc-server-developer-3.1.0.RELEASE/lib/com.springsource.org.apache.commons.configuration-1.8.0.jar
/home/axxera/sts-bundle/pivotal-tc-server-developer-3.1.0.RELEASE/lib/com.springsource.org.apache.commons.digester-1.8.1.jar
/home/axxera/sts-bundle/pivotal-tc-server-developer-3.1.0.RELEASE/lib/com.springsource.org.apache.commons.jxpath-1.3.0.jar
/home/axxera/sts-bundle/pivotal-tc-server-developer-3.1.0.RELEASE/lib/com.springsource.org.apache.commons.lang-2.6.0.jar
/home/axxera/sts-bundle/pivotal-tc-server-developer-3.1.0.RELEASE/lib/com.springsource.org.apache.commons.logging-1.1.1.jar
/home/axxera/sts-bundle/pivotal-tc-server-developer-3.1.0.RELEASE/lib/com.springsource.org.bouncycastle.jce-1.46.0.jar
/home/axxera/sts-bundle/pivotal-tc-server-developer-3.1.0.RELEASE/lib/com.springsource.org.bouncycastle.mail-1.46.0.jar
/home/axxera/sts-bundle/pivotal-tc-server-developer-3.1.0.RELEASE/lib/com.springsource.org.jdom-1.0.0.jar
/home/axxera/sts-bundle/pivotal-tc-server-developer-3.1.0.RELEASE/lib/commons-codec-1.6.jar
/home/axxera/sts-bundle/pivotal-tc-server-developer-3.1.0.RELEASE/lib/commons-logging-1.1.3.jar
/home/axxera/sts-bundle/pivotal-tc-server-developer-3.1.0.RELEASE/lib/httpclient-4.3.3.jar
/home/axxera/sts-bundle/pivotal-tc-server-developer-3.1.0.RELEASE/lib/httpcore-4.3.2.jar
/home/axxera/sts-bundle/pivotal-tc-server-developer-3.1.0.RELEASE/lib/jackson-annotations-2.1.1.jar
/home/axxera/sts-bundle/pivotal-tc-server-developer-3.1.0.RELEASE/lib/jackson-core-2.1.1.jar
/home/axxera/sts-bundle/pivotal-tc-server-developer-3.1.0.RELEASE/lib/jackson-databind-2.1.1.jar
/home/axxera/sts-bundle/pivotal-tc-server-developer-3.1.0.RELEASE/lib/joda-time-2.7.jar
/home/axxera/sts-bundle/pivotal-tc-server-developer-3.1.0.RELEASE/lib/tc-runtime-instance-3.1.0.RELEASE.jar
/home/axxera/Venkat/Libraries/org-apache-commons-logging.jar
/home/axxera/Venkat/Libraries/org.springframework.context-3.0.4.RELEASE.jar
/home/axxera/Venkat/Libraries/spring-context-4.1.5.RELEASE.jar
/home/axxera/Venkat/Libraries/jbehave-spring-3.6.4.jar
/home/axxera/Venkat/Libraries/commons-logging-1.2/commons-logging-1.2.jar
/home/axxera/Venkat/Libraries/commons-logging-1.2/commons-logging-1.2-javadoc.jar
以下是我的代码
主类
package com.spring;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Main {
public static void main(String[] args) {
ClassPathXmlApplicationContext appContext =
new ClassPathXmlApplicationContext("Beans.xml");
}
}
package com.spring;
public class SpringSample {
void printMessage() {
System.out.println("Hello World");
}
}
beans.xml中:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="SampleBean" class="com.spring.SpringSample"></bean>
</beans>
答案 0 :(得分:1)
看起来你错过了spring-beans-<version>.jar
。下载并将其添加到类路径中。