context:component-scan" is not bound

后端 未结 5 881
北海茫月
北海茫月 2020-12-05 13:49

Am new to spring and I know this question has been asked many times, but I had to ask it again.

I guess,I have done appropriate namespace declarations, but still fac

相关标签:
5条回答
  • 2020-12-05 14:16

    You are missing Context (http://www.springframework.org/schema/context) namespace there :

    <beans:beans xsi:schemaLocation="http://www.springframework.org/schema/mvc       http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd   
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd   
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd 
    
    
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
    

    Add the last line from this code.

    0 讨论(0)
  • 2020-12-05 14:17

    Yes, you must add

    http://www.springframework.org/schema/context
    

    Before

    http://www.springframework.org/schema/context/spring-context-3.0.xsd
    

    So it looks like :

    <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-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    
    0 讨论(0)
  • 2020-12-05 14:17

    For All time Sake not just simply copy and past. But.

    First see that which comment you used in your xml file.Let say your xml contains the following...

    1. <context:component-scan base-package="com.spring.study" />
    2. <context:annotation-config/>
    3. <mvc:annotation-driven />

    Then before you copy and past code see that what your really need in the header <beans:beans section ...

    So ,Do it like this which satisfies the above configuration setting and

    Make sure you clean and build every time after you change your 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:mvc="http://www.springframework.org/schema/mvc"
        xmlns:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/task
        http://www.springframework.org/schema/task/spring-task-3.2.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.2.xsd">
    
        <mvc:annotation-driven />
        <context:component-scan base-package="com.spring.study" />
        <bean
            class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="prefix" value="/WEB-INF/jsp/" />
            <property name="suffix" value=".jsp" />
        </bean>
    
    </beans>
    

    Cheers! Dman!

    0 讨论(0)
  • 2020-12-05 14:30

    Add the context namespace declaration to the beans tag definition in the application context file

    <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-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd">  
    
    0 讨论(0)
  • 2020-12-05 14:35

    You should add xmlns:context="http://www.springframework.org/schema/context" into your beans xml.

    0 讨论(0)
提交回复
热议问题