@Bean
public DataSource h2DataSource(){
PooledDataSource dataSource = new PooledDataSource();
dataSource.setDriver("org.h2.Driver");
dataSource.setUrl("jdbc:h2:database/h2db");
dataSource.setUsername("sa");
dataSource.setPassword("");
return dataSource;
}
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!--引入外部配置文件-->
<properties resource="jdbc.properties">
<!--配置属性-->
<property id="driver" value="com.mysql.jdbc.Driver"/>
<property id="url" value="jdbc:mysql://localhost:3306/mybatis"/>
<property id="username" value="root"/>
<property id="password" value="password"/>
</properties>
<!--设置-->
<settings>
<setting id="cacheEnabled" value="true"/>
</settings>
<!--定义类别名-->
<typeAliases>
<typeAlias alias="userInfo" type="com.tianxing.database.dao.result.UserInfo"/>
<!--自动扫描-->
<package id="mybatis.pojo"/>
</typeAliases>
<!--default标明默认启用哪个数据源配置-->
<environments default="development">
<!--可配置多个数据源-->
<environment id="development">
<transactionManager type="JDBC">
<property id="autoCommit" value="false"/>
</transactionManager>
<dataSource type="POOLED">
<property id="driver" value="com.mysql.jdbc.Driver"/>
<property id="url" value="jdbc:mysql://10.130.131.27:3306/mybatis"/>
<property id="username" value="root"/>
<property id="password" value="password"/>
</dataSource>
</environment>
</environments>
</configuration>