Classpath ! it does not exist !

유재영·2021년 11월 14일
0

전에는 문제 없이 실행되던 프로젝트였는데 다시 실행하려고 보니
servlet-context.xml 파일의 classpath 가 없다는 것.

[classpath:/mybatis/mapper/*.xml]: class path resource [mybatis/mapper/] cannot be resolved to URL because it does not exist

검색을 해보니 해결하는 다양한 방법이 있었다.

  • 유형1
    classpath:mybatis/mapper/.xml 를
    classpath:/mybatis/mapper/
    .xml "/"를 붙여서 사용하라는 글
  • 유형2
    value="classpath: " 를
    value="classpath*: " 이렇게 적으라는 글

나는 둘다 안돼고 유형2 같은경우 해당 단계는 넘어가지만 추후에 해당 서비스의 맵퍼파일에 접근하려고 할때 아래와 같은 또 다른 에러와 마주했다.

org.apache.ibatis.binding.BindingException: Type interface mybatis.MainImpl is not known to the MapperRegistry.

그래서 classpath*: 는 적용하지 않으면서 근본적인 해결책을 찾은 방법을 기록한다.
classpath 경로는 변경그대로 두고 ,
pom.xml 의 안에 내용을 추가하면 된다.
위치는 위에 위치하면된다.


<!-- Mybatis 빈 생성 -->
<beans:bean id="sqlSessionFactory"
	class="org.mybatis.spring.SqlSessionFactoryBean">
<beans:property name="dataSource" ref="dataSource"/>
<beans:property name="mapperLocations" 
                value="classpath:mybatis/mapper/*.xml"/>
</beans:bean>	

<!-- pom.xml -->
<build>
  <resources>
      <resource>
          <directory>src/main/resources</directory>
          <includes>
              <include>**/*.properties</include>
              <include>**/*.xml</include>
              <include>**/*.tld</include>
          </includes>
          <filtering>false</filtering>
      </resource>
      <resource>
          <directory>src/main/java</directory>
          <includes>
              <include>**/*.properties</include>
              <include>**/*.xml</include>
              <include>**/*.tld</include>
          </includes>
          <filtering>false</filtering>
      </resource>
  </resources>
  <plugins>
    ...
  </plugins>
</build>

잘못된 내용 또는 더 좋은 방법에 대해 의견주시면 감사하겠습니다.
도움이 되셨다면 좋아요를 눌러주세요.

profile
🤤🤤🤤

0개의 댓글