* Spring and MyBatis integration maven project Complete article is available in http://inprogress.baeldung.com/wp-admin/post.php * Spring-MyBatis integration example This code demonstrates how to use MyBatis in Sring environment. Full details could be found in article http://inprogress.baeldung.com/?p=31706&preview=true
54 lines
2.7 KiB
XML
54 lines
2.7 KiB
XML
<?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"
|
|
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx"
|
|
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
|
|
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
|
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
|
|
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
|
|
|
|
<mvc:annotation-driven />
|
|
<context:component-scan base-package="com.baeldung.spring.mybatis" />
|
|
<bean
|
|
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
|
|
<property name="prefix" value="/WEB-INF/jsp/" />
|
|
<property name="suffix" value=".jsp" />
|
|
</bean>
|
|
<!-- <bean id="dataSource"
|
|
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
|
|
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
|
|
<property name="url" value="jdbc:mysql//localhost:3306/baeldung;" />
|
|
<property name="username" value="root" />
|
|
<property name="password" value="admin" />
|
|
</bean> -->
|
|
|
|
|
|
<bean id="dataSource"
|
|
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
|
|
|
|
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
|
|
<property name="url" value="jdbc:mysql://localhost:3306/baeldung" />
|
|
<property name="username" value="root" />
|
|
<property name="password" value="admin" />
|
|
</bean>
|
|
|
|
<tx:annotation-driven transaction-manager="transactionManager" />
|
|
<bean id="transactionManager"
|
|
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
|
|
<property name="dataSource" ref="dataSource" />
|
|
</bean>
|
|
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
|
|
<property name="dataSource" ref="dataSource" />
|
|
<property name="typeAliasesPackage" value="com.baeldung.spring.mybatis.model" />
|
|
<property name="mapperLocations" value="classpath*:com/baeldung/spring/mappers/*.xml" />
|
|
</bean>
|
|
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
|
|
<constructor-arg index="0" ref="sqlSessionFactory" />
|
|
</bean>
|
|
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
|
|
<property name="basePackage" value="com.baeldung.spring.mybatis.mappers" />
|
|
</bean>
|
|
|
|
<bean id="studentService" class="com.baeldung.spring.mybatis.service.StudentServiceImpl"></bean>
|
|
|
|
</beans> |