错误:cvc-elt.1.a:找不到元素“beans”的声明

问题描述 投票:0回答:1

添加此代码时,出现此错误,我尝试将 beans:beans 添加到标签中,但随后出现相同的错误,请帮我解决这个问题

<?xml version="1.0" encoding="UTF-8"?>
<beans  xmlns:beans="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:context="http://www.springframework.org/schema/context"
        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">

    <bean id="testBean"
        class="alishev.spring.demo.TestBean">
        <constructor-arg value="Neil"/>
    </bean>

</beans>
java xml spring javabeans
1个回答
1
投票

您拥有

xmlns:beans="http://www.springframework.org/schema/beans"
,这意味着您需要为该命名空间中的所有标签添加前缀
beans:

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

    <bean id="testBean"
        class="alishev.spring.demo.TestBean">
        <constructor-arg value="Neil"/>
    </bean>

</beans>
© www.soinside.com 2019 - 2024. All rights reserved.