添加此代码时,出现此错误,我尝试将 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>
您拥有
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>