1.配置日志文件
log4j.rootLogger=DEBUF, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n2.首先配置数据库配置文件
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc.mysql://127.0.0.1:3306/mybatis jdbc.username=XXXX jdbc.password=XXXX3.配置Mybatis的配置文件
<configuration>
<!-- 配置别名 --> <typeAliases> <!-- 批量扫描别名 --> <package name="xxx.xxxx.xxxx.po类的路径"/> <!-- <package name="XXX"/> --> </typeAliases> <!-- 配置mapper,由于使用spring和mybatis的整合包进行mapper扫描,故不需要配置 必须遵循:mapper.xml和mapper.java文件同名且在一个目录--> <!-- <mappers></mappers> --> </configuration>4.配置dao层文件
(1)加载数据库配置文件
<context:property-placeholder location="classpath:db.properties" />
<!--
<bean id="propertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:db.properties</value>
</list>
</property>
<property name="fileEncoding" value="UTF-8" />
</bean>
<bean id="configurer" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list><value>classpath:db.properties</value></list></property></bean>
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">
<property name="properties" ref="configurer"/></bean>
-->
<!-- 配置数据源 dbcp -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${jdbc.driver}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> <property name="maxActive" value="30" /> <property name="maxIdle" value="5" /> </bean>