[Spring]org.springframework.beans.factory.UnsatisfiedDependencyException

eunoia73·2024년 9월 21일

trouble shooting

목록 보기
4/16

❗️ 에러문구

  • org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'joinController': Unsatisfied dependency expressed through field 'joinService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'joinService': Unsatisfied dependency expressed through field 'memberRepository'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined Invocation of init method failed; nested exception is java.io.IOException: Failed to parse mapping resource
  • sqlSessionFactory 빈을 생성하는 과정에서 SQL.Contact.xml 파일을 읽는 중 문제가 발생했음을 나타낸다. MyBatis에서 SQL 매핑 파일을 파싱할 때 발생하는 오류이다.
  • 새로운 기능 구현을 위해 새로운 controller, service, repository, dto, sql.xml 생성 후 발생
  • context-beans.xml 파일에 basePackage는 추가했다.

context-beans.xml

	<!-- DAO 위치를 basePackage로.. -->
	<!-- 작업지시서가 있는 패키지 위치를 잡아줘야 사용 할 수 있다 -->
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage"
			value="com.portfolio.www.auth.dao.mybatis, com.portfolio.www.board.dao.mybatis,
			 com.portfolio.www.contact.dao.mybatis" />
	</bean>

💡 에러 해결 방법

  • 추가한 코드
    mybatis-config.xml 파일에 dto를 추가하지 않았음..!

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>
		<!-- member_id -> memberId -->
		<setting name="mapUnderscoreToCamelCase" value="true" />
	</settings>
	<!-- 쿼리 수행 결과를 DTO에 자동 매핑하기 위해 DTO 검색 -->
	<typeAliases>
		<package name="com.portfolio.www.auth.dto" />
		<package name="com.portfolio.www.board.dto" />
 		<package name="com.portfolio.www.contact.dto" />
	</typeAliases>
</configuration>

0개의 댓글