The configuration file is as follows:
The Base-context.xml file is as follows:
<?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 "> <!--used to activate bean--> registered in the container <!--<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 as follows:
<?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>
The Persistence-context.xml file is as follows:
<?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 "> <!--database basic information Configuration -- < 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}" /> <!--Initialize the number of connections -- < property name="InitialSize" value="Ten"/> <!--The maximum number of concurrent connections -- < property name="maxactive" value="/> " < minimum number of idle connections!-- < property name="Minidle" value="/> " <!--configuration Gets the time that the connection waits timeout-- < property name="maxwait" value="/> " <!--time limit is recycled -- < property name="removeabandoned" value="true"/> <!--How long does it exceed the time limit; < property name="Removeabandonedtimeout" value="120000" /> < How long!--configuration interval to detect idle connections that need to be closed, in milliseconds-and < property name="Timebetweenevictionrunsmillis" value="60000" /> <!--Configure the minimum time for a connection to survive in a pool, in milliseconds- - < property name="Minevictableidletimemillis" value="40000" /> <!--SQL used to detect if a connection is valid, a query statement is required- - < property name="Validationquery" value="Select 1"/> <!--detect when you apply for a connection < property name="Testwhileidle" value="true"/> <!--perform validationquery to detect if the connection is valid when the connection is requested, configuring true will degrade performance and < property name="Testonborrow" value="false"/> <!--When the connection is returned, the Validationquery detection connection is valid, and configuring true will degrade performance and < property name="Testonreturn" value="false"/> <!--open Pscache and specify the size of Pscache on each connection- < property name="poolpreparedstatements" value="true" /> < property name="Maxpoolpreparedstatementperconnectionsize"value= "/>" <!--property type is a string, the extension is configured by alias, common plug-ins are: Filter:stat log used for monitoring statistics filter:log4j anti- Imperial SQL injection Filter:wall-- < property name="Filters" value="stat"/> </Bean></Beans>
Below the mappers is the MyBatis XML file, when it starts up with an error:
Property‘configLocationnotdefaultConfiguration
The solution is as follows:
<bean id = "sessionfactory" class = " Org.mybatis.spring.SqlSessionFactoryBean " > <property name = ref = "DataSource" /> <property name = value=/> <property name = value=/> </bean>
Under Sessionfactory, add:
<propertyname="configLocation" value="classpath:spring/persistence-context.xml"/>
Add Persistence-context.xml location, or all files in one file
MyBatis exception-property ' configlocation ' not specified, using default MyBatis Configuration