◆ root-context.xml ( Mybatis 연결 추가 )
페이지 정보

본문
<?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:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mybatis-spring="http://mybatis.org/schema/mybatis-spring"
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.3.xsd
http://mybatis.org/schema/mybatis-spring http://mybatis.org/schema/mybatis-spring-1.2.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<!-- <property name="driverClassName" value="com.mysql.jdbc.Driver"></property> -->
<!-- <property name="url" value="jdbc:mysql://localhost:3306/spring"></property> -->
<property name="driverClassName" value="org.mariadb.jdbc.Driver"></property>
<property name="url" value="jdbc:mariadb://localhost:3306/spring"></property>
<property name="username" value="root"></property>
<property name="password" value="1111"></property>
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
</bean>
</beans>
[ 설명 ]
Mybatis 와 Mysql 연동 작업
Mybatis 와 스프링 연동 작업에서의 핵심은 Connecton을 생성하고, 처리하는 SQLSessionFactroy의 존재
SQLSessionFactroy는 데이터베이스와의 연결과 SQL의 실행에 대한 모든 것을 가진 가장 중요한 객체
스프링을 이용할 때는 SQLSessionFactroy를 생성해 주는 특별한 객체를 설정해 주는데 SqlSessionFactoryBean 클래스 사용
추가설명
MyBatis 에서 가장 핵심적인 객체는 SQLSession 이라는 존재와 SQLSessionFactroy 입니다.
SQLSessionFactroy 의 이름에서 보듯이 내부적으로 SQLSession 이라는 것을 만들어 내는 존재.
SQLSession 을 통해서 Connection 을 생성하거나 원하는 SQL 을 전달하고, 결과를 리턴 받는 구조로 작성한다.
패키지명을 보면 MyBatis 의 패키지가 아니라 스프링과 연동 작업을 처리하는 mybatis.spring 라이브러리의 클래스임을 알 수 있습니다.
- 이전글◆ root-context.xml ( mapper 설정 추가 ) 24.07.16
- 다음글◆ root-context.xml ( mybatis-spring 체크 , DB 연결 : DataSource 설정 ) 24.07.16
댓글목록
등록된 댓글이 없습니다.