IDEA下Maven项目整合Spring和MyBatis出现jdbc.properties is invalid;前言中不允许有内容
来源:互联网 发布:nginx优化 2016 编辑:程序博客网 时间:2024/05/18 01:57
在Idea下用Maven
管理Spring
和MyBatis
整合的项目,在Junit
测试service层代码时不会出错,但把整个项目发布到Tomcat
时抛出各种各样的异常,花了最多时间的异常为:
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 1 in XML document from class path resource [jdbc.properties] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; 前言中不允许有内容。
Caused by: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; 前言中不允许有内容。
解决此异常的思路
检查项目中的各类配置文件
首先检查spring框架的配置文件applicationContext.xml,一开始有异常的配置文件如下:
<?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" 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"> <!--c3p0数据源(properties文件配置)--> <!--<context:property-placeholder location="classpath:jdbc.properties"/>--> <context:property-placeholder location="jdbc.properties"/> <bean id="c3p0Datasource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="driverClass" value="${jdbc.driver}"/> <property name="jdbcUrl" value="${jdbc.url}"/> <property name="user" value="${jdbc.user}"/> <property name="password" value="${jdbc.password}"/> </bean> <!--c3p0数据源(直接配置)--> <!--<bean id="c3p0Datasource" class="com.mchange.v2.c3p0.ComboPooledDataSource">--> <!--<property name="driverClass" value="com.mysql.jdbc.Driver"/>--> <!--<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/conference"/>--> <!--<property name="user" value="root"/>--> <!--<property name="password" value="qwer123456"/>--> <!--</bean>--> <!-- 创建-SqlSessionFactory对象 --> <bean id="mysqlSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="configLocation" value="classpath:mybatis.xml"/> <property name="dataSource" ref="c3p0Datasource"/> </bean> <!-- 生成Dao代理对象--> <bean id="userinfoDao" class="org.mybatis.spring.mapper.MapperFactoryBean"> <property name="sqlSessionFactory" ref="mysqlSqlSessionFactory"/> <property name="mapperInterface" value="modeldao.UserinfoDao"/> </bean> <!-- 扫描式动态代理--> <!-- 配置为指定包中的所有接口生成代理对象--> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="sqlSessionFactoryBeanName" value="mysqlSqlSessionFactory"/> <property name="basePackage" value="modeldao"/> </bean> <bean id="scurityGuaranteeService" class="service.ScurityGuaranteeService"> <property name="dao" ref="securityGuaranteeDao"/> </bean></beans>
初始有异常的web.xml配置文件如下:
<?xml version="1.0" encoding="UTF-8" ?><web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> <display-name>Archetype Created Web Application</display-name> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml classpath:jdbc.properties</param-value> </context-param> <!-- 注册ServletContext监听器--> <!-- 1. 在ServletContext被创建时,创建Spring容器对象--> <!-- 2. 把创建的Spring容器对象放入Application域中--> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list></web-app>
jdbc.properties内容如下:
jdbc.driver = com.mysql.jdbc.Driverjdbc.url = jdbc:mysql://localhost:3306/conferencejdbc.user = rootjdbc.password = qwer123456
解决方法
正确配置截图
阅读全文
0 0
- IDEA下Maven项目整合Spring和MyBatis出现jdbc.properties is invalid;前言中不允许有内容
- Intellij IDEA 启动出现“前言中不允许有内容”
- IDEA的Maven项目整合Spring和Mybatis框架出现ibatis.binding.BindingException: Invalid bound statement (not found)
- spring整合mybatis报错Cause: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; 前言中不允许有内容
- dos中mybatis generator自动生成出现xml parsers Error 前言中不允许有内容解决方法
- mybatis逆向工程出现XML Parser Error on line 1: 前言中不允许有内容。
- Spring boot mybatis集成报错Caused by: org.xml.sax.SAXParseException: 前言中不允许有内容
- 启动tomcat是出现:Could not clean server of obsolete files: 前言中不允许有内容。前言中不允许有
- Idea中Maven整合Spring+mybatis+tomcat
- Spring+mybatis+maven整合过程加载配置文件jdbc.properties
- IntelliJ IDEA使用Maven创建Spring和Mybatis工程出现...BindingException: Invalid bound statement (not found)
- Nested exception: 前言中不允许有内容。
- 关于前言中不允许有内容
- SAXParseException:前言中不允许有内容
- Intellij IDEA 在电脑蓝屏死机重启后报前言中不允许有内容的BUG解决方法
- IntelliJ IDEA 14.0.2 死机重启后报前言中不允许有内容的BUG解决方法
- 关于 SAXParseException Content is not allowed in Prolog (前言中不允许有内容)
- spring和mybatis整合加载jdbc.properties异常
- 最小编辑代价
- Maven-(安装、配置)
- 读书笔记之深入理解Java虚拟机
- TextView的跑马灯效果
- HADOOP简明教程——HDFS集群搭建实战
- IDEA下Maven项目整合Spring和MyBatis出现jdbc.properties is invalid;前言中不允许有内容
- 分布式架构
- Python爬虫学习--urllib的基本使用笔记
- js实现左右切换页面
- atcoder-Coloring Dominoes(组合数学)
- Web服务器
- window.onresize使用实例
- 数据分析之微信通讯录分析
- PAT乙级(Basic Level)真题 >A+B和C (15)