【问题标题】:Builds fine but error while server deployment : XML issue在服务器部署时构建正常但出错:XML 问题
【发布时间】:2016-05-25 22:00:24
【问题描述】:

我尝试创建一个简单的 Web 服务,但在尝试运行它时发生了以下错误,在 Tomcat 7spring-webmvc-4.2.4

错误:

描述资源路径位置类型 cvc-complex-type.2.4.c:
匹配通配符是严格的,但找不到声明
元素“上下文:组件扫描”。 mvc-dispatcher-servlet.xml /example/src/main/SpringMVC/src/main/webapp/WEB-INF 第12行XML问题

描述资源路径位置类型cvc-complex-type.2.4.c:匹配通配符是严格的,但找不到元素'mvc:annotation-driven'的声明。 mvc-dispatcher-servlet.xml /example/src/main/SpringMVC/src/main/webapp/WEB-INF 第14行XML问题

pom.xml

<project xmlns="http://maven.apache.org/POM/4.2.4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.2.4 http://maven.apache.org/maven-v4_2_4.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.arpit.java2blog</groupId>
  <artifactId>SpringRestfulWebServicesWithJSONExample</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>SpringRestfulWebServicesWithJSONExample Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>2.7.0</version>
</dependency>

  </dependencies>
    <build>
        <finalName>SpringRestfulWebServicesWithJSONExample</finalName>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>${jdk.version}</source>
                    <target>${jdk.version}</target>
                </configuration>
            </plugin>
        </plugins>

    </build>
    <properties>
        <spring.version>4.2.4.RELEASE</spring.version>
        <jdk.version>1.8</jdk.version>
    </properties>


    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-core</artifactId>
                <version>2.7.0</version>
                <type>bundle</type>
            </dependency>
        </dependencies>
    </dependencyManagement>
</project>

POM 也有以下交战。

文档中没有引用语法约束(DTD 或 XML 架构)。

springrest-servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:context="http://www.springframework.org/schema/context"
 xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 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 http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

 <mvc:annotation-driven/>
<context:component-scan base-package="org.arpit.java2blog.controller" />

</beans>

web.xml

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
  <display-name>Archetype Created Web Application</display-name>
  <servlet>
 <servlet-name>springrest</servlet-name>
 <servlet-class>
  org.springframework.web.servlet.DispatcherServlet
 </servlet-class>
 <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
 <servlet-name>springrest</servlet-name>
 <url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>

【问题讨论】:

  • 你能出示你的mvc-dispatcher-servlet.xml吗?
  • 已添加。请检查。
  • @mars 你也可以发布你的 web.xml 吗?

标签: java xml spring maven spring-mvc


【解决方案1】:

在您的pom.xml 中,您将Spring 4.2.4.RELEASE 用作:

 <properties>
        <spring.version>4.2.4.RELEASE</spring.version>
        <jdk.version>1.8</jdk.version>
 </properties>

在您的springrest-servlet.xml 中,您指的是Spring 3.x DTD。

<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:context="http://www.springframework.org/schema/context"
 xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 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 http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

用 Spring 4.x 架构替换您的 DTD,如下所示:

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

【讨论】:

    猜你喜欢
    • 2020-07-29
    • 1970-01-01
    • 2020-01-01
    • 2018-10-22
    • 2013-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-30
    相关资源
    最近更新 更多