org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)

■ org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):

 
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): net.iotinfra.pilot1.mappertest1.SampleMapper.viewSample
    at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:178)
...
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
...
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for net.iotinfra.pilot1.mappertest1.SampleMapper.viewSample
    at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:775)
   ...
    at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:176)
    ... 34 more

■ 여러가지 원인이 있겠지만 여기서는 maven 빌드시에 src/main/java안에 **Mapper.xml이 위치하고 있었고 이 파일이 컴파일(?)되지 않아 target디렉토리에 **Mapper.xml 파일이 없었다. 그래서 위의 에러 메세지가 발생했다. 해결 방법은 pom.xml 파일에 아래와 같이 컴파일시에 **Mapper.xml 파일이 포함되도록 추가하면 된다.

<project>
...
<build>
<resources>
    <resource>
        <directory>src/main/java</directory>
        <includes>
            <include>**/*.xml</include>
        </includes>
    </resource>
    <resource>
        <directory>src/main/resources</directory>
        <includes>
            <include>**/*.xml</include>
            <include>**/*.properties</include>
            <include>**/*.setting</include>
        </includes>
    </resource>
</resources>
</build>   
</project>

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다