Spring v3 no declaration can be found for element 'mvc:resources'

后端 未结 5 1057
广开言路
广开言路 2020-12-01 14:23

Currently Running

Tomcat: v6

Spring Tools Suite: v2.7.2

Spring Framework: spring-webmvc-3.0.5

Servlet XML

 

        
相关标签:
5条回答
  • 2020-12-01 14:24

    I was getting the same error. The cause was the missing Maven dependency spring -webmvc. I included the below dependency and it started working.

            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-webmvc</artifactId>
                <version>${spring.version}</version>
            </dependency>
    
    0 讨论(0)
  • 2020-12-01 14:25

    I have enroled for spring course on udemy. I followed every step that my instructor show me to do. So if you are using spring mvc and hibernate you may encounter this error Failed to read schema document 'http://www.springframework.org/schema/tx/spring-tx.xsd' etc for:

    <mvc:annotation-driven/> and <tx:annotation-driven transaction-manager="myTransactionManager" /> elements
    

    in my spring configuration file i had these two urls

        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd
    
        http://www.springframework.org/schema/tx 
        http://www.springframework.org/schema/tx/spring-tx.xsd
    

    in xsi:schemaLocation, which i replaced with

        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
    
        http://www.springframework.org/schema/tx 
        http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
    

    actually i visited these two sites http://www.springframework.org/schema/mvc/ and http://www.springframework.org/schema/tx/ and just added the latest version of spring-mvc and spring-tx i.e, spring-mvc-4.2.xsd and spring-tx-4.2.xsd

    So, in my opinion specifying version no explicitly is a good practice. It worked for me, hope this works for you too. Thank you.

    0 讨论(0)
  • 2020-12-01 14:31

    In your spring context xml mvc namespace url should match url in schemaLocation. Something like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:mvc="http://www.springframework.org/schema/mvc"
           xsi:schemaLocation="
             http://www.springframework.org/schema/mvc
             http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
    

    This is a standard XML namespace declaration. The namespace url is sort of an unique id, which is then mapped to the actual schema location in xsi:schemaLocation.

    0 讨论(0)
  • 2020-12-01 14:32

    When using Spring namespaces urls I normally do not use version information and that works most of the time pretty well. You might like to try the namespace url

    http://www.springframework.org/schema/mvc/spring-mvc.xsd
    

    instead of

    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
    
    0 讨论(0)
  • 2020-12-01 14:40

    I think your schemaLocation mapping is incorrect. The namespace is specified as:

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

    which is correct, I believe, but in the schemaLocation you have

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

    So if you change the first line of the schemaLocation mapping to your mvc namespace, it should work fine.

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