Logs

[Tomcat / IntelliJ] The origin server did not find a current representation for the target resource or is not willing to disclose that one exists. 404 error 해결하는 법

랩실외톨이 2023. 11. 17. 05:14
반응형

 

 

 

The origin server did not find a current representation for the target resource or is not willing to disclose that one exists. 

 

이 에러가 나는 경우는 보통 경로의 문제이다.

대부분의 사람들은 tomcat의 context root의 경로가 틀렸기 때문에 경로를 제대로 못 찾아서 에러가 났다.

하지만 나는 제대로 설정했기 때문에 문제가 아니었다.

 

 

분명히 Application context가 "/"로 잘 설정되어 있는데 무엇이 문제였을까?

 

바로 IntelliJ의 프로젝트명.iml 파일에 경로가 잘못 설정되어 있었기 때문이다.

 

<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
  <component name="FacetManager">
    <facet type="web" name="Web">
      <configuration>
        <descriptors>
          <deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/web/WEB-INF/web.xml" />
        </descriptors>
        <webroots>
           <root url="file://$MODULE_DIR$/src/main/webapp" relative="/" />
        </webroots>
        <sourceRoots>
          <root url="file://$MODULE_DIR$/src/main/java" />
          <root url="file://$MODULE_DIR$/src/main/resources" />
        </sourceRoots>
      </configuration>
    </facet>
  </component>
</module>

 

 

SpringMVC로 구조를 바꾸고 나면 자동으로 이렇게 iml 파일이 작성되고 이를 기반으로 경로가 설정되고 돌아간다.

(아마도 이클립스의 servlet-context랑 같은 역할을 하는 걸지도...?)

 

 

 

 

반응형

 

 

 

 

이때 <webroots> 태그 안에 있던 root가 틀렸다.

진짜 어이없는 게 이렇게 설정파일을 만들어줬으면 처음에 프로젝트 구조 자동으로 생성해 줄 때 저 구조대로 만들어줬어야 하는데 위의 web.xml의 경로를 보면 알 수 있듯 /src/main/webapp이 아니라 그냥 /web으로 프로젝트 파일을 만들어줬다.

 

 <root url="file://$MODULE_DIR$/web" relative="/" />

 

 

그래서 코드를 이렇게 수정해 줬더니 코드가 잘 돌아갔다.

(역대급 노어이)

 

 

 

반응형