본문 바로가기
Spring 게시판 기초

1. Oracle 연동하기

by dantriss 2022. 10. 1.

https://github.com/Dantriss/basic

Java : 1.8

Orac : 11g

tomcat :  8.5

 

 

 

pom.xml

<!-- 오라클 JDBC 드라이버 properties 시작 전 -->
	<repositories>
	  <repository>
	   <id>oracle</id>
	   <url>http://maven.jahia.org/maven2</url>
	  </repository>
	</repositories>


----------------------------------------------------------------------------
		<!-- 스프링에서 JDBC  -->
		<dependency>
		   <groupId>org.springframework</groupId>
		   <artifactId>spring-jdbc</artifactId>
		   <version>${org.springframework-version}</version>
		</dependency>
        
        <!-- 컨넥션 풀 라이브러리 -->
		<dependency>
		    <groupId>commons-dbcp</groupId>
		    <artifactId>commons-dbcp</artifactId>
		    <version>1.4</version>
		</dependency>
		
		<!-- 오라클 JDBC 드라이버 -->
		<dependency>
		    <groupId>com.oracle</groupId>
		    <artifactId>ojdbc7</artifactId>
		    <version>12.1.0.2</version>
		</dependency>

		<!-- MyBatis 라이브러리 -->
		<dependency>
		    <groupId>org.mybatis</groupId>
		    <artifactId>mybatis</artifactId>
		    <version>3.4.1</version>
		</dependency>
		
		<!-- mybatis spring 연동 -->
		<dependency>
		    <groupId>org.mybatis</groupId>
		    <artifactId>mybatis-spring</artifactId>
		    <version>1.3.0</version>
		</dependency>

        <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok 롬복 -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.24</version>
            <scope>provided</scope>
        </dependency>

        <!--annotaion   -->
            <dependency>
                <groupId>javax.annotation</groupId>
                <artifactId>javax.annotation-api</artifactId>
                <version>1.3.2</version>
            </dependency>

 

servlet-context.xml

<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
	<resources mapping="/resources/**" location="/resources/" />

	<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
	<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<beans:property name="prefix" value="/WEB-INF/views/" />
		<beans:property name="suffix" value=".jsp" />
	</beans:bean>
	
	<context:component-scan base-package="com.project" />

 

 

root-context.xml

 

 

<!-- 데이터베이스 연결 --> 
	<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:@127.0.0.1:1521:xe" /> 
		<property name="username" value="test1"/> 
		<property name="password" value="tiger"/> 
	</bean>
	
	<!-- SqlSession --> 
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> 
		<property name="dataSource" ref="dataSource" />
		
		<!-- MyBatis 설정 파일의 위치를 지정합니다. -->
		<property name="configLocation" value="classpath:/mybatis-config.xml" />
		
		<!-- SQL 파일의 위치를 지정합니다. -->
		<property name="mapperLocations" value="classpath:/mapper/*.xml" />
	</bean>
	
	<!-- SqlSession -->
	<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate" destroy-method="clearCache"> 
		<constructor-arg name="sqlSessionFactory" ref="sqlSessionFactory" /> 
	</bean>
	
	<!-- 지정된 베이스 패키지에서 DAO(Mapper) 를 검색하여 등록합니다. -->
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> 
		<property name="basePackage" value="com.project.service.dao" /> 
	</bean>
	
	<!-- 트랜잭션 매니저 bean 을 등록합니다. -->
	<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> 
		<property name="dataSource" ref="dataSource" /> 
	</bean>
	
	<!-- 아노테이션 기반의 트랜잭션을 사용합니다. --> 
	<tx:annotation-driven transaction-manager="transactionManager"/>

 

src/main/resources에 mybatis-config.xml 생성

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
 PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
 "http://mybatis.org/dtd/mybatis-3-config.dtd">

<configuration>
    <settings>
          <setting name="mapUnderscoreToCamelCase" value="true"/>
    </settings>
    <typeAliases>
          <typeAlias alias="projectVO" type="com.project.vo.ProjectVO"/>
    </typeAliases>
</configuration>

 

 

 

 

해당프로젝트를 하면서 참고한 블로그 : https://integer-ji.tistory.com/341?category=750983

'Spring 게시판 기초' 카테고리의 다른 글

프로젝트 다운로드후 링크 눌렀을때 404 error  (0) 2022.10.05
3. 웹에서 쓴 글 DB에 등록하기  (0) 2022.10.05
2. 출력해보기  (2) 2022.10.01
0. 프로젝트 생성  (0) 2022.10.01

댓글