Error: cvc-elt.1.a: Cannot find the declaration of element 'beans'

97 Views Asked by At

when adding this code, this error appears, I tried adding beans:beans to the tag, but then the same error appears, please help me solve this problem

<?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>
1

There are 1 best solutions below

2
seenukarthi On

You are having xmlns:beans="http://www.springframework.org/schema/beans" which means you need to prefix beans: to all tags from that namespace.

Remove the :beans from xmlns:beans="http://www.springframework.org/schema/beans" so your XML should be as follows

<?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>