0

私は MyEclipse 8.6.1 を使用しています: これは私の 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"
xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/beans     http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">


<bean id="addr" class="info.inetsolv.Address" abstract="false"
    lazy-init="default" autowire="default" dependency-check="default"
    p:street="bk guda" p:city="hyd" p:state="ap">
</bean></beans>

これは私の Java プログラムです: package info.inetsolv;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

public class MyAppSprContnr {

public static void main(String[] args) {
  Resource resource = new ClassPathResource("applicationContext.xml");  
  BeanFactory container= new XmlBeanFactory(resource);
  System.out.println("container"+container);
}

}

これは私が得ている例外です

log4j:WARN No appenders could be found for logger      (org.springframework.beans.factory.xml.XmlBeanDefinitionReader).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main"       org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 11 in XML   document from class path resource [applicationContext.xml] is invalid; nested exception is   org.xml.sax.SAXParseException: cvc-complex-type.3.2.2: Attribute 'dependency-check' is not   allowed to appear in element 'bean'.
at org.springframework.b

これを解決するには?

4

2 に答える 2

5

このdependency-check属性は Spring 以降非推奨になり3.0ました。次の回避策は、同等の機能を提供できます

  • コンストラクター (setter インジェクションではなくコンストラクター インジェクション) を排他的に使用して、適切なプロパティが設定されるようにします。
  • 専用の init メソッドが実装されたセッターを作成します。
  • @Requiredプロパティが必要な場合は、注釈付きのセッターを作成します。
  • @Autowiredデフォルトで必要なプロパティも意味する - ドリブン インジェクションを使用します。

関連: @必須の例

于 2012-12-25T19:50:21.433 に答える
0

依存関係がSpring 3で廃止されたことに同意しますが、Spring 4までテストし、Spring 5で削除されました.

すべての場合に必要になる可能性のあるすべてのコンポーネントを必須と見なすため、依存関係チェックのデメリットのため、@Required アノテーションを使用することを好みます。

于 2020-03-29T17:41:39.233 に答える