ibatis中有两种数据源加载方式,分别在sql-map-config.xml文件中配置如下:
1, 通过jndi方式加载数据源:
- <transactionManager type="JDBC">
- <dataSource type="JNDI">
- <property name="DataSource" value="java:jdbc/cisa"/>
- dataSource>
- transactionManager>
其中:JNDI是web container中初始化的datasource 的jndi,也可以直接配置jdbc,如下:
- <transactionManager type="JDBC">
- <dataSource type="SIMPLE">
- <property name="JDBC.Driver" value="oracle.jdbc.driver.OracleDriver"/>
- <property name="JDBC.ConnectionURL" value="jdbc:oracle:thin:@192.168.1.19:1521:boxer"/>
- <property name="JDBC.Username" value="cisa"/>
- <property name="JDBC.Password" value="admin"/>
- <property name="Pool.MaximumActiveConnections" value="10"/>
- <property name="Pool.MaximumIdleConnections" value="5"/>
- <property name="Pool.MaximumCheckoutTime" value="120000"/>
- <property name="Pool.TimeToWait" value="500"/>
- <property name="Pool.PingQuery" value="select 1 from user"/>
- <property name="Pool.PingEnabled" value="false"/>
- <property name="Pool.PingConnectionsOlderThan" value="1"/>
- <property name="Pool.PingConnectionsNotUsedFor" value="1"/>
- dataSource>
- transactionManager>
2,通过jdbc.properties文件加载datasource,等同与1中的第二中加载方式:
xml 代码
- <properties resource="properties/database.properties"/>
- <transactionManager type="JDBC">
- <dataSource type="SIMPLE">
- <property value="${driver}" name="JDBC.Driver"/>
- <property value="${url}" name="JDBC.ConnectionURL"/>
- <property value="${username}" name="JDBC.Username"/>
- <property value="${password}" name="JDBC.Password"/>
- dataSource>
- transactionManager>
其中:database.properties是jdbc配置文件,内容如下:
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost/jpetstore
username=root
password=
3,ibatis缓存配置:
xml 代码
- <settings
- cacheModelsEnabled="true"
- enhancementEnabled="true"
- lazyLoadingEnabled="true"
- errorTracingEnabled="true"
- maxRequests="10"
- maxSessions="5"
- maxTransactions="3"
- useStatementNamespaces="false"
- />
<sqlmapconfig></sqlmapconfig>