JAVA

gradle oracle mybatis 설정

양상추상츄 2023. 5. 2. 22:34
 

스프링부트 처음에 프로젝트 설정하기

예전에 학원에서 했던 내용을 다시 시간이 지나서 해봄 (현재 보다는 이전의 버전으로 설치진행) 1. gradle 설치 Gradle | Releases Find binaries and reference documentation for current and past versions of Gradle. gradle.or

rizni.tistory.com

스프링부트 설정후에 mybatis를 설정하고 테스트를 하던중 여러가지 오류가 복합적으로 계속 나와서 애를 먹었다.

 

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'springConfig' defined in file ...

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource ...

 

위와 같이 bean이 등록이 안됐다고 하거나 dataSource 설정이 잘못 되었다거나 하나의 오류를 해결하기 위해 이것 저것 해보다 보니 복합적으로 문제가 발생하는듯 했다.

 

그중에 체크를 해서 해결이 되었던 부분을 정리함

 

계속 잘못 설정했던것 중에 하나가 dependencies 설정을 잘못했었다.

내가 가지고 있는 OJDBC는 OJDBC6 인데 계속 다른 버전을 입력해놓고 있었다.

ojdbc가 해당 경로에 존재하는지도 확인하자 (경로는 검색해서 확인)

 

 

1. build.gradle 체크하기 

plugins {
  id 'org.springframework.boot' version '2.6.0'
  id 'io.spring.dependency-management' version '1.0.11.RELEASE'
  id 'java'
  id 'eclipse'
  id "io.freefair.lombok" version "6.4.1"
}

group = 'com.items'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

repositories {
  mavenCentral()
}

dependencies {	
  // Oracle JDBC 드라이버
  implementation group: 'com.oracle.database.jdbc', name: 'ojdbc6', version: '11.2.0.4'
  implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.2.2'
  
  // log4j2
  implementation 'org.springframework.boot:spring-boot-starter-log4j2'
  
  implementation 'org.springframework.boot:spring-boot-starter-jdbc'
  implementation 'org.springframework.boot:spring-boot-starter-web'
  developmentOnly 'org.springframework.boot:spring-boot-devtools'
  testImplementation 'org.springframework.boot:spring-boot-starter-test'
  testImplementation 'junit:junit:4.13.2'
}

configurations {
    all {
        exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
    }
}

test {
  useJUnitPlatform()
}

build.gradle을 수정하고 나서는 다시 build 해줘야한다.

cmd를 통해서 해당 경로(프로젝트에 app 폴더, app 폴더 안에 보면 build.gradle 있음)로 이동한 다음 gradle clean eclipse 하고 gradle eclipse로 실행

 

 

2. @SpringBootApplication 애노테이션을 main class에 사용했는지 확인하기

@SpringBootApplication은 아래의 모든 애노테이션 역할을 함

@SpringBootConfiguration => Bean 설정

@ConponentScan => @Service, @Repository, @Controller를 스캔하여 Bean으로 등록

@EnableAutoConfiguration => 사전에 정의한 Bean들을 자동 등록

.... 그 외의 다른 애노테이션도 있음

 

 

3. Controller, Service, Dao 각각 @Autowired 사용 확인하기

@Inject @name을 사용하여 의존 객체 주입가능 @Inject는 프레임워크에 종속적이지 않다고 한다.

@Autowired는 SpringBoot에 종속적이다.

 

 

4. 경로 설정이 잘되있는지 확인하기

com > items > dao 경로가 같음

 

5. xml에 있는 쿼리문이 정상작동하는지 확인하기