MyBatis异常-Property 'configLocation' not specified, using default MyBatis Configuration
来源:互联网 发布:php 获取数组元素 编辑:程序博客网 时间:2024/06/08 03:09
配置文件如下:
base-context.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-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!--用于激活容器中注册的bean--> <!--<context:annotation-config/>--> <context:property-placeholder location="classpath*:/props/*.properties" ignore-unresolvable="true"/> <context:component-scan base-package="com.ufind.server.*"> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/> </context:component-scan></beans>
db-mybatis.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" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="mapperLocations" value="classpath:mybatis/mappers/*.xml"/> </bean> <bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.ufind.server.infra.repository.sql"/> <property name="sqlSessionFactoryBeanName" value="sessionFactory"/> </bean></beans>
persistence-context.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" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="dataSourceTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"/> </bean> <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"> <!-- 数据库基本信息配置 --> <property name="driverClassName" value="${db.jdbc.driver}"/> <property name="url" value="${db.jdbc.connection.url}"/> <property name="username" value="${db.jdbc.username}"/> <property name="password" value="${db.jdbc.password}"/> <!-- 初始化连接数量 --> <property name="initialSize" value="10"/> <!-- 最大并发连接数 --> <property name="maxActive" value="100"/> <!-- 最小空闲连接数 --> <property name="minIdle" value="20"/> <!-- 配置获取连接等待超时的时间 --> <property name="maxWait" value="5000"/> <!-- 超过时间限制是否回收 --> <property name="removeAbandoned" value="true"/> <!-- 超过时间限制多长; --> <property name="removeAbandonedTimeout" value="120000"/> <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 --> <property name="timeBetweenEvictionRunsMillis" value="60000"/> <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 --> <property name="minEvictableIdleTimeMillis" value="40000"/> <!-- 用来检测连接是否有效的sql,要求是一个查询语句--> <property name="validationQuery" value="select 1"/> <!-- 申请连接的时候检测 --> <property name="testWhileIdle" value="true"/> <!-- 申请连接时执行validationQuery检测连接是否有效,配置为true会降低性能 --> <property name="testOnBorrow" value="false"/> <!-- 归还连接时执行validationQuery检测连接是否有效,配置为true会降低性能 --> <property name="testOnReturn" value="false"/> <!-- 打开PSCache,并且指定每个连接上PSCache的大小 --> <property name="poolPreparedStatements" value="true"/> <property name="maxPoolPreparedStatementPerConnectionSize" value="50"/> <!--属性类型是字符串,通过别名的方式配置扩展插件,常用的插件有: 监控统计用的filter:stat 日志用的filter:log4j 防御SQL注入的filter:wall --> <property name="filters" value="stat"/> </bean></beans>
在mappers下边是mybatis的xml文件,启动的时候出现错误:
DEBUG o.m.spring.SqlSessionFactoryBean - Property 'configLocation' not specified, using default MyBatis Configuration
解决方式如下:
<bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="mapperLocations" value="classpath:mybatis/mappers/*.xml"/> <property name="configLocation" value="classpath:spring/persistence-context.xml"/> </bean>
在sessionFactory下加入:
<property name="configLocation" value="classpath:spring/persistence-context.xml"/>
添加persistence-context.xml的位置即可,或者所有的文件都在一个文件即可
4 0
- MyBatis异常-Property 'configLocation' not specified, using default MyBatis Configuration
- mybatis疑难杂症之配置文件无限加载 Property 'configLocation' not specified, using default MyBatis Configuration
- mybatis configuration
- Mybatis Configuration
- mybatis Configuration
- Mybatis异常 Parameter "..." not found
- mybatis not find getter for property。。。
- mybatis 异常:Invalid bound statement (not found) .
- Mybatis异常:Invalid bound statement (not found)
- mybatis 异常 Invalid bound statement (not found)
- 深入浅出MyBatis-Configuration
- 深入浅出MyBatis-Configuration
- 深入浅出MyBatis-Configuration
- MyBatis -- configuration配置详解
- 深入浅出MyBatis-Configuration
- myBatis源码之Configuration
- mybatis:configuration xml
- 深入浅出MyBatis-Configuration
- 友盟分享——微信、腾讯微博、新浪微博分享失败原因分析
- 移动端企业IM系统优化
- 如何区分Java中的值传递和引用传递
- CSS3属性之text-overflow:ellipsis详解
- iOS-Sandbox
- MyBatis异常-Property 'configLocation' not specified, using default MyBatis Configuration
- [2016/03/14] 2015蓝桥杯省赛A组Java语言 真题略解
- 迭代器逆置容器元素
- Android中LayoutInflater类的inflate方法的使用及注意事项
- 【2016年Esri开发者大会亮点解析】Runtime Quartz,下一代的ArcGIS Runtime SDKs
- java文件读写操作大全
- 面试中的 10 大排序算法总结-->http://write.blog.csdn.net/postedit?ref=toolbar
- 51nod1080 两个数的平方和
- 安卓五种存储方式入门