If you like to know detail to implement this sample with Spring framework, please follow mybatis-integration-with-spring.
<?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:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd"> <!-- JNDI datasource --> <!-- <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName" value="jdbc/oraclePool" /> <property name="resourceRef" value="true" /> </bean> --> <!-- Hsql datasource --> <!-- <jdbc:embedded-database id="dataSource"> <jdbc:script location="classpath:hsql/schema.sql" /> <jdbc:script location="classpath:hsql/data.sql" /> </jdbc:embedded-database> --> <!-- Oracle JDBC datasource --> <!-- <bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource"> <property name="driverClass" value="oracle.jdbc.OracleDriver" /> <property name="url" value="jdbc:oracle:thin:@HOST:1111:ORA" /> <property name="username" value="ID" /> <property name="password" value="PASSWORD" /> </bean> --> <!-- mysql JDBC datasource --> <!-- <bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource"> <property name="driverClass" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost:3306/mydata" /> <property name="username" value="user123" /> <property name="password" value="12345678" /> </bean> --> <!-- sqlite JDBC datasource --> <!-- <bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource"> <property name="driverClass" value="org.sqlite.JDBC" /> <property name="url" value="jdbc:sqlite:C:/yourdb.sqlite" /> </bean> --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="typeAliasesPackage" value="com.devtrigger.model" /> <property name="mapperLocations" value="classpath*:dao/**/*.xml" /> </bean> <bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate"> <constructor-arg index="0" ref="sqlSessionFactory" /> </bean> <!-- scan for mapper interface files and let them be autowired --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.devtrigger.dao" /> </bean> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> </beans>
No comments:
Post a Comment