Search code examples
javaspringservletscomponent-scan

"cvc-complex-type.2.4.c: matching wildcard is strict, but no declaration can be found for element 'context:component-scan'."


I get the following error in my spring-servlet.xml

The matching wildcard is strict, but no declaration can be found for element 'context:component-scan'.

My spring-servlet.xml has the following:

<?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"
       xmlns:oauth="http://www.springframework.org/schema/security/oauth2" 
       xmlns:sec="http://www.springframework.org/schema/security"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:tx="http://www.springframework.org/schema/tx"

       xsi:schemaLocation="
       http://www.springframework.org/schema/security/oauth2 
       http://www.springframework.org/schema/security/spring-security-oauth2-1.0.xsd
       http://www.springframework.org/schema/mvc 
       http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
       http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
       http://www.springframework.org/schema/security 
       http://www.springframework.org/schema/security/spring-security-3.1.xsd
       http://www.springframework.org/schema/beans 
       http://www.springframework.org/schema/beans/spring-beans-3.1.xsd  
       http://www.springframework.org/schema/context 
       http://www.springframework.org/schema/context/spring-context.xsd ">



    <!-- Scans the classpath of this application for Spring annotations such 
        as @Component, @Service, @Controller and @Repositry to deploy as beans. For 
        example, the ClaimsService is annotated with @Service("claimsService") which 
        means that spring will automatically create a bean with the name claimsService. 
    -->
    <context:component-scan base-package="org.springframework.security.oauth" />

i have all the dependancies downloaded


Solution

  • The problem is with the namespaces check for the version of the spring jars added and the namespaces. Especially for the schema location of the context namespace,

    xmlns:context="http://www.springframework.org/schema/context"
    

    please have a look into the spring docs to configure namespaces for spring security also . don't add any un-neccesary namespaces