Skip to content

Commit

Permalink
mybatis
Browse files Browse the repository at this point in the history
  • Loading branch information
callor committed Apr 17, 2024
1 parent 7ccc4d4 commit 22374f2
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 9 deletions.
49 changes: 49 additions & 0 deletions Settings/mybatis/mybatis-context0.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?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:mybatis-spring="http://mybatis.org/schema/mybatis-spring"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://mybatis.org/schema/mybatis-spring http://mybatis.org/schema/mybatis-spring-1.2.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/tx https://www.springframework.org/schema/tx/spring-tx-4.3.xsd">


<!--
mybatis 5.x의 최소한의 요소만으로 DBMS 와 연동하기 위한 설정
-->

<!-- 1 dataSource 생성, MySQL 8.x -->
<bean id="ds" class="org.apache.commons.dbcp2.BasicDataSource">
<property name="driverClassName" value="com.mysql.cj.jdbc.Driver"/>
<property name="username" value="root"/>
<property name="password" value="root_Password"/>
<property name="url" value="jdbc:mysql://localhost:3306/bbsDB"/>
</bean>

<!-- 2. sqlSession을 관리할 관리자 생성 -->
<!-- typeAliasesPackage : value로 설정된 패키지에 있는 모든 DTO, VO 클래스를 자동으로 Alias 등록 -->
<!-- mapperLocation : xml 방식의 SQL mapper 경로 설정 -->
<bean id="factoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="ds"/>
<property name="typeAliasesPackage" value="com.callor.bbs.models"/>
<property name="mapperLocations" value="/WEB-INF/spring/mapper/*-mapper.xml"/>
</bean>

<!-- mapper.xml과 Dao와 연동하여 DBMS 연산을 수행 -->
<bean class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="sqlSessionFactory" />
</bean>

<!-- Dao interface 를 Scan 하여 실제 DBMS 핸들링 코드를 작성해 둔다 -->
<mybatis-spring:scan base-package="com.callor.bbs.dao"/>

<!-- Transaction 설정 -->
<tx:annotation-driven/>
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="ds"/>
</bean>

</beans>
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,9 @@
<bean id="sqlSessionFactory"
class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="ds" />
<property name="mapperLocations"
value="/WEB-INF/spring/mybatis/mapper/*-mapper.xml" />

<property name="configLocation"
value="/WEB-INF/spring/mybatis/mybatis-config.xml" />

<property name="typeAliasesPackage"
value="com.callor.product.domain" />

<property name="mapperLocations" value="/WEB-INF/spring/mybatis/mapper/*-mapper.xml" />
<property name="configLocation" value="/WEB-INF/spring/mybatis/mybatis-config.xml" />
<property name="typeAliasesPackage" value="com.callor.product.domain" />
</bean>

<!-- mapper.xml과 Dao와 연동하여 DBMS 연산을 수행 -->
Expand Down

0 comments on commit 22374f2

Please sign in to comment.