关于tomcat启动报配置文件错误的问题

异常如下
Caused by: org.xml.sax.SAXParseException; lineNumber: 15; columnNumber: 71; 文档根元素 "beans" 必须匹配 DOCTYPE 根 "null"。

spring 配置文件如下
<?xml version="1.0" encoding="UTF-8"?>

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.3.xsd">

<!-- 引入配置文件 -->
<bean id="propertyConfigurer"
      class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="classpath:jdbc.properties" />
</bean>

<!-- 3. 数据源dataSource  C3P0 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
    <property name="driverClass" value="${jdbc.driverClassName}"/>
    <property name="jdbcUrl" value="${jdbc.url}"/>
    <property name="user" value="${jdbc.username}"/>
    <property name="password" value="${jdbc.password}"/>

    <property name="maxPoolSize" value="${c3p0.pool.maxPoolSize}"/>
    <property name="minPoolSize" value="${c3p0.pool.minPoolSize}"/>
    <property name="initialPoolSize" value="${c3p0.pool.initialPoolSize}"/>
    <property name="acquireIncrement" value="${c3p0.pool.acquireIncrement}"/>
</bean>

<!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <!-- 自动扫描mapping.xml文件 -->
    <property name="mapperLocations" value="classpath:*.xml"></property>
    <property name="typeAliasesPackage" value="cn.com.domain"/>
</bean>

<!-- DAO接口所在包名,Spring会自动查找其下的类 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage" value="cn.com.dao" />
    <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
</bean>

<!-- (事务管理)transaction manager, use JtaTransactionManager for global tx -->
<bean id="transactionManager"
      class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource" />
</bean>

web.xml配置如下

<?xml version="1.0" encoding="UTF-8"?>
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
Restful Web Application

<filter>
    <filter-name>characterEncodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
    <init-param>
        <param-name>forceEncoding</param-name>
        <param-value>true</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>characterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:application-context.xml</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
    <servlet-name>jersey-serlvet</servlet-name>
    <servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
    <init-param>
        <param-name>com.sun.jersey.config.property.packages</param-name>
        <param-value>cn.com</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>jersey-serlvet</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

jar包如下
图片说明

6个回答

格式错了,给你个模板

 <?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:tx="http://www.springframework.org/schema/tx"
    xmlns:aop="http://www.springframework.org/schema/aop"
    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/tx 
        http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/aop 
        http://www.springframework.org/schema/aop/spring-aop.xsd">

    <!-- 引入配置文件 -->
    <bean id="propertyConfigurer"
         class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location" value="classpath:jdbc.properties" />
    </bean>

</beans>
Dalton2017
Dalton2017 回复govdoo: 谢谢,我也不知道为什么,突然就好了
一年多之前 回复
govdoo
govdoo 一般跟spring的xml 放一起 mybatis.xml: <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> </configuration>
一年多之前 回复
Dalton2017
Dalton2017 回复govdoo:引入了mybatis空配置,还是报错了
一年多之前 回复
Dalton2017
Dalton2017 回复govdoo:这个标签放在哪里面
一年多之前 回复
govdoo
govdoo 回复Dalton2017: 我大概知道了,虽然你把spring 和mybatis配置在一起,但是mybatis的主配置文件还是需要的啊,哪怕mybatis.xml里没配置东西。<property name="configLocation" value="classpath:mybatis.xml" />
一年多之前 回复
Dalton2017
Dalton2017 回复govdoo: 我spring 和mybatis配置在一起的,没加上mybatis是不报错的,加上了mybatis就报错了,不清楚是不是配置文件的错误,还是jar包冲突的问题
一年多之前 回复
govdoo
govdoo 回复Dalton2017: 你这个似乎是 mybatis的个错误,参考:https://blog.csdn.net/u012561176/article/details/80557839
一年多之前 回复
Dalton2017
Dalton2017 回复govdoo: 我试试看,谢谢
一年多之前 回复
govdoo
govdoo 配置文件格式没有问题,那就是 jar 包冲突导致的了。请参考:https://www.cnblogs.com/yishuiqy/p/4220959.html
一年多之前 回复
Dalton2017
Dalton2017 回复govdoo: 谢谢,按照你的格式来了。但是还是报错误 Caused by: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 15; columnNumber: 68; 文档根元素 "beans" 必须匹配 DOCTYPE 根 "null"。
一年多之前 回复
govdoo
govdoo 注意 beans 位置
一年多之前 回复

spring配置文件少了beans根标签

 <beans></beans>
Lei_Da_Gou
Lei_Da_Gou 不客气
一年多之前 回复
lzmcsdnlzm
lzmcsdnlzm 谢谢
一年多之前 回复
Dalton2017
Dalton2017 回复Lei_Da_Gou: 好,我试试看
一年多之前 回复
Lei_Da_Gou
Lei_Da_Gou 看什么?版本在pom.xml中修改,dependcy下有个version标签
一年多之前 回复
Dalton2017
Dalton2017 谢谢,那个标签我复制的时候自动帮我忽略了,我新上传了一张图片,spring jar包版本都是3.0.5的,麻烦帮忙看下
一年多之前 回复

重新配置TOMCAT...

应该是“<" 与“>"不匹配,你看看是不是某个地方多了或者少了 </>

<?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.3.xsd">

<!-- 引入配置文件 -->
<bean id="propertyConfigurer"
      class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="classpath:jdbc.properties" />
</bean>

<!-- 3. 数据源dataSource  C3P0 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
    <property name="driverClass" value="${jdbc.driverClassName}"/>
    <property name="jdbcUrl" value="${jdbc.url}"/>
    <property name="user" value="${jdbc.username}"/>
    <property name="password" value="${jdbc.password}"/>

    <property name="maxPoolSize" value="${c3p0.pool.maxPoolSize}"/>
    <property name="minPoolSize" value="${c3p0.pool.minPoolSize}"/>
    <property name="initialPoolSize" value="${c3p0.pool.initialPoolSize}"/>
    <property name="acquireIncrement" value="${c3p0.pool.acquireIncrement}"/>
</bean>

<!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <!-- 自动扫描mapping.xml文件 -->
    <property name="mapperLocations" value="classpath:*.xml"></property>
    <property name="typeAliasesPackage" value="cn.com.domain"/>
</bean>

<!-- DAO接口所在包名,Spring会自动查找其下的类 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage" value="cn.com.dao" />
    <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
</bean>

<!-- (事务管理)transaction manager, use JtaTransactionManager for global tx -->
<bean id="transactionManager"
      class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource" />
</bean>

自动帮我忽略了那个标签
图片说明

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问