development♥/[Java Spring]게시판 만들기

sqlSessionFactory 에러 오류 해결방법 [Spring Junit Test]

리니❤ 2022. 9. 30. 09:02
반응형

 

 

 

 

Junit으로 테스트하기위해 아래 파일 3개를 만들었는데

 

DataSourceTest.java

DBTest.java

MybatisTest.java

 

이 파일 3개를 통해서 지금까지한 기본셋팅이 잘 돌아가는지 확인하려면

 

 

 

 

 

1. DBTest.java

 

일단 DBTest.java 에서

파일을 연 상태에서 

 

화면에 마우스 우측클릭 > Run as > Junit Test

(여기서 주의할건 테스트 문서들은 Run as > Run on Server 가 아니라 Run as > Junit Test 로 해야한다.)

 

DBTest.java 파일같은 경우는 다이렉트로 연결되기때문에 문제없이 콘솔창에 뜸  

 

 

 

 

2. DataSourceTest.java   

    MybatisTest.java

 

우측에 Junit에러나 나오고 왼쪽 콘솔창에는 에러메시지가 보임 

 

 

에러 문구 

Error creating bean with name 'sqlSessionFactory' defined in file [C:\Users\ntsys\eclipse-workspace\BBS\src\main\webapp\WEB-INF\spring\root-context.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.lang.String' to required type 'org.springframework.core.io.Resource[]' for property 'mapperLocations'; nested exception is java.lang.IllegalArgumentException: Could not resolve resource location pattern [classpath:/mappers/**/*.xml]: class path resource [mappers/] cannot be resolved to URL because it does not exist

 

 

아래보면 classpath:/mappers/**/*.xml를 찾을 수 없다는데 root-context.xml파일에 설정 잡아준거대로

mappers폴더가 있고 그안에 폴더가 있고 그안에 xml파일이 있어야하는데 그게 없다는거라서

만들어줘야함 

 

Could not resolve resource location pattern [classpath:/mappers/**/*.xml]: class path resource [mappers/] cannot be resolved to URL because it does not exist

 

 

 

해결방법 : 본인이  root-context.xml문서에서 작성한 classpath의 경로대로 파일들이 만들어져있어야함

나는 classpath:/mappers/**/*.xml 이렇게 적어놨기때문에 

resources폴더에 > mappers라는 폴더에 > 아무폴더있고 > xml이라는 파일 만들어놔야함

 

 

 

 

 

 

 

mapper.xml파일 만들고

안에 비어있으면 안됨

 

처음에 xml파일 만들면

<?xml version="1.0" encoding="UTF-8"?> 딱 이부분만 나오는데

 

아래코드를 적어주고 파일안이 비어있지않게 해야함

 

-----------------------------------------------------------------------------

<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ntsys.bbs.mapper">

</mapper>

-------------------------------------------------------------------------------

여기에서 com.ntsys.bbs 이부분은 자신이 만든것에 맞게 작성해야함

 

 

 

 

 

****이 부분이 작성되어야 마이바티스 사용가능****
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">

 

 

 

 

 

 

 

 

 

 

 

 

 

반응형