Spring Project에 설정파일 3개를 수정해야 합니다.( root-context.xml , pom.xml , web.xml )
1. root-context.xml (root로 되어있는곳에 사용할 id와 password를 입력해야 합니다.)
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:@localhost:1521:DB명" />
<property name="username" value="root"/>
<property name="password" value="root"/>
</bean>
1-1. sqlSessionFactory를 넣어주고, mapper 경로를 지정해줍니다.
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mapperLocations" value="classpath:/**/*.xml" />
</bean>
1-2. SqlSession을 구현하고 코드에서 SqlSession를 대체하는 역할을 하는 MyBatis 연동 모듈을 추가해준다.
<bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="sqlSessionFactory" />
</bean>
2. pom.xml (메이븐 설정)
<repositories>
<repository>
<id>mesir-repo</id>
<url>http://mesir.googlecode.com/svn/trunk/mavenrepo</url>
</repository>
</repositories>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${org.springframework-version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.2.8</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.4.0</version>
</dependency>
3. web.xml (Servlet맵핑을 위한 설정)
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
'DB' 카테고리의 다른 글
Reletion 관계에서 NULL 처리 (0) | 2019.04.24 |
---|---|
[MySQL] LAST_INSERT_ID(), insert 후 PK 값 사용하기 (0) | 2017.03.23 |
MYSQL 여러 ROW를 하나의 컬럼에 ,(콤마)로 구분하여 저장하고 View하기 (0) | 2017.03.15 |
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server (0) | 2017.03.10 |
Spring 프로젝트에 Mysql DB 연동하는 방법 (0) | 2017.03.10 |