当前位置: 首页 > 知识库问答 >
问题:

CVC-complex-type.2.4.a:发现以元素“resources”开头的内容无效

咸亦
2023-03-14

我刚开始使用spring,我现在正在使用Spring4

一旦将war部署到JCS-SaaS(云)中,我将得到以下错误:

org.springframework.beans.factory.XML.xmlBeanDefinitionStoreException:类路径资源[pepsiservlet-context.XML]的XML文档中的第33行无效;嵌套异常是org.xml.sax.SAXParseException;行号:33;列号:62;CVC-complex-type2.4.a:发现以元素“resources”开头的内容无效。应为“{”http://www.springframework.org/schema/beans“:导入、”http://www.springframework.org/schema/beans“:别名、”http://www.springframework.org/schema/beans“:bean、WC[##其他:”http://www.springframework.org/schema/beans“]、”http://www.springframework.org/schema/beans“:beans}”之一。

原因:org.xml.sax.SAXParseException;行号:33;列号:62;CVC-complex-type2.4.a:发现以元素“resources”开头的内容无效。应为“{”http://www.springframework.org/schema/beans“:导入、”http://www.springframework.org/schema/beans“:别名、”http://www.springframework.org/schema/beans“:bean、WC[##其他:”http://www.springframework.org/schema/beans“]、”http://www.springframework.org/schema/beans“:beans}”之一。

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.itc</groupId>
    <artifactId>pepsiIndIntegration</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>pepsiIndIntegration Maven Webapp</name>
    <url>http://maven.apache.org</url>

    <properties>
        <jdk.version>1.7</jdk.version>
        <spring.version>4.1.7.RELEASE</spring.version>
        <slf4j.version>1.7.10</slf4j.version>
        <log4j.version>1.2.17</log4j.version>
        <apache.commons.version>3.4</apache.commons.version>
    </properties>
    <dependencies>
        <!-- JUnit Dependency -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>

        <!-- Spring Dependencies -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>4.0.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib</artifactId>
            <version>2.2.2</version>
        </dependency>


        <!-- Logging Dependencies -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>${slf4j.version}</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>${log4j.version}</version>
        </dependency>

        <!-- Spring MVC -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib</artifactId>
            <version>2.2.2</version>
        </dependency>

        <!-- Org Apache Commons -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>${apache.commons.version}</version>
        </dependency>

        <!-- Oracle Driver Dependency -->
        <!-- <dependency> <groupId>oracle</groupId> <artifactId>ojdbc6</artifactId> 
            <version>1.0</version> <scope>system</scope> <systemPath>${oracle.driver.path}</systemPath> 
            </dependency> -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
        </dependency>

        <!-- Dependency for common file upload -->
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.2.2</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.4</version>
        </dependency>
        <!-- <dependency> <groupId>net.sf.ehcache</groupId> <artifactId>ehcache</artifactId> 
            <version>2.9.1</version> </dependency> -->
    </dependencies>
    <build>
        <finalName>pepsiIndIntegration</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.2</version>
                <configuration>
                    <source>${jdk.version}</source>
                    <target>${jdk.version}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>sonar-maven-plugin</artifactId>
                <version>2.5</version>
            </plugin>
            <plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-xjc-plugin</artifactId>
                <version>3.1.2</version>
                <configuration>
                    <extensions>
                        <extension>org.apache.cxf.xjcplugins:cxf-xjc-dv:3.1.2</extension>
                    </extensions>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-codegen-plugin</artifactId>
                <version>3.1.2</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>wsdl2java</goal>
                        </goals>
                        <configuration>
                            <sourceRoot>${basedir}/target/generated-sources/cxf/wsdl2java</sourceRoot>
                            <!-- <sourceRoot>${basedir}/target/generated-sources/cxf/wsdl2java</sourceRoot> -->
                            <!-- <defaultOptions> <bindingFiles> <bindingFile>${binding}/binding.xml</bindingFile> 
                                </bindingFiles> </defaultOptions> -->
                            <wsdlRoot>${wsdls}</wsdlRoot>
                            <wsdlOptions>
                                <wsdlOption>
                                    <wsdl>https://someurl:someport/xyz/abc?wsdl</wsdl>
                                    <extraargs>
                                        <extraarg>-client</extraarg>
                                    </extraargs>
                                </wsdlOption>
                            </wsdlOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

下面是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>
  <!-- Loading Beans -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            classpath:pepsiBeans.xml
        </param-value>
    </context-param>

    <!-- Spring Dispatched Servlet -->
    <servlet>
        <servlet-name>pepsiServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:pepsiServlet-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>pepsiServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:task="http://www.springframework.org/schema/task"
    xmlns:util="http://www.springframework.org/schema/util"
    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
        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
        http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
    <context:component-scan base-package="com.test.pepsi" />
    <!-- DispatcherServlet Context: defines this servlet's request-processing 
        infrastructure -->

    <!-- Enables the Spring MVC @Controller programming model -->
    <mvc:annotation-driven />

    <!-- Enable Annotation based Declarative Transaction Management -->
    <tx:annotation-driven proxy-target-class="true"
        transaction-manager="transactionManager" />

    <!-- Creating TransactionManager Bean, since JDBC we are creating of type 
        DataSourceTransactionManager -->
    <beans:bean id="transactionManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <beans:property name="dataSource" ref="dataSource" />
    </beans:bean>

    <!-- Handles HTTP GET requests for /resources/** by efficiently serving 
        up static resources in the ${webappRoot}/resources directory -->
    <resources mapping="/resources/**" location="/resources/" />
    <!-- Initialization for data source -->
<!--    <beans:bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <beans:property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
        <beans:property name="url"
            value="jdbc:oracle:thin@hostname:port:service/sid" />
        <beans:property name="username" value="USER_NAME" />
        <beans:property name="password" value="PASSWORD" />
    </beans:bean> -->

    <beans:bean id="messageSource"
        class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <beans:property name="basename" value="classpath:ApplicationMessages" />
        <beans:property name="defaultEncoding" value="UTF-8" />
    </beans:bean>


    <task:annotation-driven scheduler="scheduler"
        executor="executor" />
    <task:scheduler id="scheduler" pool-size="10" />
    <task:executor id="executor" pool-size="10" />


    <task:scheduled-tasks scheduler="scheduler">
        <task:scheduled ref="pepsiIntgService" method="readFile"
            cron="${cronstring}" />
    </task:scheduled-tasks>

    <!-- <bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor"> 
        <property name="corePoolSize" value="5" /> <property name="maxPoolSize" value="10" 
        /> <property name="queueCapacity" value="25" /> </bean> <bean id="taskExecutorExample" 
        class="TaskExecutorExample"> <constructor-arg ref="taskExecutor" /> </bean> -->
</beans:bean>

共有1个答案

宇文鸣
2023-03-14

我在xml文件中看到两个问题:

您的结束标记不正确,它应该是:

</beans:beans> (not </beans:bean>)

因此,与pepsiservlet-context.XML对应的XML文档格式不正确,因此无法解析。

<mvc:resources mapping="/resources/**" location="/resources/" />
 类似资料: