【问题标题】:Spring Example using STS 3.6.4使用 STS 3.6.4 的 Spring 示例
【发布时间】:2015-05-19 13:11:45
【问题描述】:

从 Spring Tool Suite 3.6.4 开始,我正在尝试开发一个 Spring 项目,我已经完成了所有工作,例如在 STS lib 文件夹和 apache common-logging 1.1.3 和 1.2 中添加 jars。

STS 在主类中显示错误 new ClassPathXmlApplicationContext("Beans.xml");

当我尝试解决它时,STS 显示配置 BuildPath 我已通过观看 Youtube 中的教程添加了所有 jar。

我使用的是 JAVA 1.6 版本,操作系统 Ubuntu,STS 3.6.4 下面列出了我添加到 buildpath 的 jar

/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>

【问题讨论】:

  • 是完整的错误信息吗?
  • 抱歉耽搁了,下面是完整的错误信息 Exception in thread "main" java.lang.Error: Unresolved compiler questions: org.springframework.beans.BeansException 类型无法解决。它是从所需的 .class 文件中间接引用的构造函数 ClassPathXmlApplicationContext(String) 引用了 com.spring.Main.main(Main.java:11) 处缺少的类型 BeansException
  • 只需使用 Spring Boot 和 Maven 或 Gradle。 Spring Initializr 会为你准备好一切,所以你只需要编写应用程序代码。

标签: spring jakarta-ee jar spring-tool-suite


【解决方案1】:

您好像错过了spring-beans-&lt;version&gt;.jar。下载它并将其添加到您的类路径中。

【讨论】:

    猜你喜欢
    • 2015-08-31
    • 1970-01-01
    • 1970-01-01
    • 2015-05-14
    • 2016-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-25
    相关资源
    最近更新 更多