IDEA下Maven项目整合Spring和MyBatis出现jdbc.properties is invalid;前言中不允许有内容
2017-08-20 23:51
1636 查看
在Idea下用
Caused by: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; 前言中不允许有内容。
首先检查spring框架的配置文件applicationContext.xml,一开始有异常的配置文件如下:
初始有异常的web.xml配置文件如下:
jdbc.properties内容如下:
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.Driver jdbc.url = jdbc:mysql://localhost:3306/conference jdbc.user = root jdbc.password = qwer123456
解决方法
正确配置截图
相关文章推荐
- 关于IDEA中maven整合mybatis+spring+springMVC项目中mapper文件找不到问题的解决方案(org.apache.ibatis.binding.BindingExcepti
- 使用Idea创建ssm项目,SpringMVC+Spring+MyBatis+Maven整合
- 关于IDEA工具在springboot整合mybatis中出现的Invalid bound statement (not found)问题
- idea 创建的maven+spring+mybatis项目整合 报错无法创建bean
- IDEA上搭建maven项目整合springboot+mybatis+shiro
- 使用Idea创建ssm项目,SpringMVC+Spring+MyBatis+Maven整合
- 使用Idea创建ssm项目,SpringMVC+Spring+MyBatis+Maven整合
- Spring+mybatis+maven整合过程加载配置文件jdbc.properties
- 使用Idea创建ssm项目,SpringMVC+Spring+MyBatis+Maven整合
- IDEA 创建Spring + SpringMVC + MyBatis整合maven项目
- IDEA下创建Maven项目,并整合使用Spring、Spring MVC、Mybatis框架
- SpringBoot整合Mybatis提示SAXParseException: 前言中不允许有内容
- idea maven spring+springmvc+sql server+mybatis项目配置
- SSM 框架 Maven项目 Spring整合Mybatis
- spring整合mybatis(开启包扫描器)出现db.properties配置文件失效的解决方案
- Eclipse Maven建web项目 与SSM三大框架整合教程(Spring+SpringMVC+MyBatis)
- SSM框架整合(IntellIj IDEA+Maven+Spring+SpringMVC+MyBatis)之Spring Framework
- SSM框架整合(Spring + SpringMVC + Mybatis + Maven + IDEA)
- Myeclipse创建Maven-web项目,并整合springmvc+mybatis
- 使用IDEA整合Spring+Spring MVC+Mybatis+Maven+Jetty框架的搭建