It's a terrible error. I struggled with this error for nearly a few days.
끔찍한 에러. 404 에러랑 하루종일 싸웠다.
I'm not sure. Let's first look into the reason why the 404 error occurs.
- Check the URL.
Check if the HTML is correcrtly mapped to be displayed on the screen.
@GetMapping("/main")
public String main() {
return "main";
}
}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link href="css/styles.css" rel ="stylesheet"/>
</head>
<body>
<h1>Welcome</h1>
</body>
</html>
- Check the Tomcat server.
톰캣 서버 Port number 확인
Check the post number on the tomcat server.
톰캣 서버 Port number를 확인한다.
경로: Server -> Modules -> Port Number
- Change the Tomcat General ➡️ Location settings.
경로: General -> Switch Location
- Project ➡️ Web Project Settings ➡️ Context root.
- Check the JDK path.
JDK 경로 확인
- CHeck the JDK Compiler Compliance Level and JDK Version.
JDK 컴파일러 확인
- Check the Java version compatible with Tomcat.
톰캣과 호환 가능한 Java 버전 확인
All my efforts were in vain.
I’m currently using Spring Boot version 3.1.5 (3.x.). It’s okay to use Java version 17.
I think I need to reconfigure the Tomcat version.
Looking at the Tomcat homepage, it seems I should be using Tomcat version 10.x. I was deploying on Tomcat 9.
Could this have been the issue?
현재 스프링 부트 3.1.5 버전을 사용하고 있고, Java 17 버전과 호환 가능하다.
아무래도 톰캣을 재구성해야할까 싶다.
- Switch to Tomcat version 10.1x
톰캣 버전 변경
The Spring project is not being deployed on the Tomcat server at all.
스프링 프로젝트가 톰캣에 전혀 올라가지 않는다.
- Edit Tomcat server.xml
톰캣 server.xml 수정
<Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/>
- Edint Tomcat server.xml (2)
톰캣 server.xml 수정 (2)
- Reconfirm Java environment variables
자바 환경변수 확인
🤦🏻♀️
📍 Reason for setting environment variables (환경변수를 설정하는 이유)
In order to use tools such as javac, java, etc., one needs to navigate to the path where the tool is located and execute it. To avoid this inconvenience and allow execution from any path, we set up environment variables.
Java, javc 툴 사용하기 위해선 해당 경로로 이동하여 실행해야 하는데, 환경변수를 설정하면 번거로움을 줄이고 어떤 경로에서든 실행할 수 있다.
- 파일 경로 확인
/dbConnectionTest/src/main/webapp/login.html
[localhost:8081/login.html]
로 이동하고자 했고, HTTP 404 에러가 떴었다.
원인은 webapp
폴더가 아닌 webapp/WEB-INF
폴더 안에 있었기 때문이다.
It took me three hour to display "Hello World."
The issue was with the Java environment variables, which is embarrassing. There was no problem with the tomcat server connection.
I must ensure that such a ridiculous error does not occur again.
"Hello World"를 출력하는데 세 시간이 걸렸다. 문제는 자바 환경변수였다. 부끄럽다. 톰캣 서버에는 문제가 없었다.
다시는 이런 얼토당토 않은 일이 없도록 해야한다.