Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 属性";默认依赖项检查";不允许出现在元素';豆子';_Spring - Fatal编程技术网

Spring 属性";默认依赖项检查";不允许出现在元素';豆子';

Spring 属性";默认依赖项检查";不允许出现在元素';豆子';,spring,Spring,我这里有一个奇怪的错误: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:contex

我这里有一个奇怪的错误:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       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
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">

</beans>
编辑


DOCTYPE的问题在于,当我删除它时,它是可以的,但是为什么呢?

依赖项检查属性在spring 3.0中被弃用。您可以使用构造函数注入而不是setter注入来确保设置了正确的属性,或者使用@Required注释创建setter方法,无论您在类中何时需要依赖项检查

例如:在Person类中强制使用名称依赖项

导入org.springframework.beans.factory.annotation.Required

public class Person{
    private int id;
    private String name;

    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    @Required
    public void setName(String name) {
        this.name = name;
    }
}

您确定Spring正在拾取您在问题中发布的XML文件,还是它确实拾取了另一个包含
元素的XML文件?在项目中搜索
default dependency check
以查找可能的其他XML文件。我提出了一个问题2016,使用java配置您不需要DOCTYPE,因为
beans
元素已经引用了XSD,这意味着这些XSD将用于验证XML(您不需要DTD再次验证它)。所以,只需删除DOCTYPE行。谢谢,请将其添加为答案,我将接受它。然后在您的spring配置文件中添加以下行
public class Person{
    private int id;
    private String name;

    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    @Required
    public void setName(String name) {
        this.name = name;
    }
}