[Spring Boot] 어노테이션, Mybatis 연결 시 오류 해결 방법 :: 매운코딩
728x90
300x250

PC가 포맷되어서 기존 환경설정 해두었던 것도 같이 날아갔다..~ 훨훨

다시 새로운 마음 가짐으로 다시 세팅을 하려고하는데.. 왠걸 환경세팅에서부터 오류가 너무 많이나요!!!

 

 

1. UnsatisfiedDependencyException / BeanCreationException오류

특정 필드에 의존주입이 되어 있을것으로 예상했지만 의존주입에 실패했기 때문에 발생하는 것

org.springframework.beans.factory.UnsatisfiedDependencyException: 
Error creating bean with name 'XXXService': 
Unsatisfied dependency expressed through field 'XXXMapper';

(1) 어노테이션이 없어서 나는 경우

XXXService.java 파일에 @Service 어노테이션을 넣어준다.

 

(2) 쿼리가 기재된 .xml 파일이 잘못된 경우

나의 경우 XXXmapper.xml에 오타가 있었다..

namespace에 오타가 있어서 경로를 찾지 못했던것..ㅠ 오타를 체크해볼 것

 

(3) DB 설정이 잘못된 경우

application.properties 파일에 문제가 있는 경우이다.

 

 

 

2. Error creating bean with name 'dataSource' defined 오류

 

의존성 주입이 잘 안되었거나 properties파일에 문제가 있는 경우이다.

nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'dataSource' defined 
in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: 
Bean instantiation via factory method failed;

pom.xml

		<dependency> <!-- MyBatis -->
			<groupId>org.mybatis.spring.boot</groupId>
			<artifactId>mybatis-spring-boot-starter</artifactId>
			<version>2.2.2</version>
		</dependency>
		<dependency> <!-- JDBC -->
			<groupId>com.oracle.database.jdbc</groupId>
			<artifactId>ojdbc8</artifactId>
			<scope>runtime</scope>
		</dependency>

 

application.properties 

#DB 세팅
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@localhost:1521/[DB명]
spring.datasource.username=[계정명]
spring.datasource.password=[계정비밀번호]

oracle 기준이며, MySQL은 다르다.

 

 

3. 지원되지 않는 문자 집합(클래스 경로에 orai18n.jar 추가): KO16MSWIN949

해당하는 jar다운 받거나 의존성 주입

		<dependency> <!-- ojdbc8.jar -->
			<groupId>com.oracle.ojdbc</groupId>
			<artifactId>orai18n</artifactId>
			<version>19.3.0.0</version>
		</dependency>

 

 

참고:

https://dololak.tistory.com/545

728x90

+ Recent posts