我正在使用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程序: 包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
如何解决这个问题?
答案 0 :(得分:4)
自dependency-check
以来,3.0
属性已被弃用。以下变通方法可以提供等效功能
@Required
注释创建setter。@Autowired
- 驱动注入,默认情况下也暗示必需属性。答案 1 :(得分:0)
我同意在春天3不再使用依赖关系,但是我一直测试到春天4,并且在春天5删除了依赖。
由于依赖检查的缺点,我更喜欢使用@Required批注,因为它认为所有组件在所有情况下都是必需的。