1

アプリケーションの実行中に Spring の「HelloWorld」プロジェクトを開発しようとすると、次のエラーが表示されます。

情報: クラスパス リソースから XML Bean 定義を読み込んでいます [Beans.xml] スレッド "main" で例外が発生しました

以下は私のコードです:

package com.tutorialspoint;

public class HelloWorld {
    private String message;

    public void getMessage() {
        System.out.println("your message : "+message);
    }

    public void setMessage(String message) {
        this.message = message;
    }
}

package com.tutorialspoint;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class MainApp {
    public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");

        HelloWorld obj = (HelloWorld) context.getBean("helloWorld ");
    obj.getMessage();
    // TODO Auto-generated method stub
    }
}

ApplicationContext.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-3.0.xsd">

    <bean id="helloWorld" class="com.tutorialspoint/HelloWorld">
        <property name="message" value="Hello World!"/>
    </bean>
</beans>
4

5 に答える 5

1

すべての依存jarを追加することは別として、class定義内でbean定義されたものが無効であるようです

com.tutorialspoint/HelloWorld
                  ^

成功する、

<bean id="helloWorld" class="com.tutorialspoint.HelloWorld"> 
     <property name="message" value="Hello World!"/>
</bean>

にもcontext.getBean("helloWorld ") 変更する必要がありますcontext.getBean("helloWorld")

于 2013-04-05T17:57:12.320 に答える
1

含む

spring-expression-3.1.1.Release.jar

libフォルダーの下

例として 3.1.1 を挙げましたが、最新バージョンがあればそれを使用できます。

于 2013-04-05T17:52:44.273 に答える
0

M Sach が言うように、Maven を使用していない場合は、「spring expression-X.Release.jar」を「lib」フォルダーに追加し、それを Eclipse のビルド パスに追加することを忘れないでください。

于 2014-01-21T08:47:41.630 に答える
0

spring-expression.jar に関連するこの例外は、これを追加します。

以下の依存関係をあなたに追加してくださいpom.xml

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-expression</artifactId>
    <version>5.3.8</version>
</dependency>
于 2016-02-05T10:14:01.197 に答える