0
votes

I have created a simple dynamic project without maven in eclipse. Only when I use tag context:component-scan, I face below error in Spring dispatcher file :-

schema_reference.4: Failed to read schema document 'https://www.springframework.org/schema/beans/spring-beans-4.3.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not .

Not sure from where version 4.3 is refered. I am using spring version 5.0.0.RELEASE and have added all jars in lib. Below is the content of spring dispatcher file :-

<?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">
        <context:component-scan base-package="com.example.controller"/>
        </beans>

I cant find fix for this issue. Suitable help will be appreciated.

1

1 Answers

0
votes

There are many possibilities for this problem.

  • Initially you added ..../spring-beans-4.3.xsd and then you removed the version but error is still showing. It is because eclipse is reading from cache. Try removing cache in prefences->General->Network->cache
  • Even if you project is not maven, right click on the project go to properties and add "Maven Dependencies" in your Build Path. This resolved the similar error for me once.
  • If the above two does not work for you, try copy pasting this code
<?xml version="1.0" encoding="utf-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:ctx="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd ">


    <ctx:annotation-config></ctx:annotation-config>
    <ctx:component-scan base-package="com.*"></ctx:component-scan>