-
Spring Boot 프로젝트 빌드하기Java 2020. 11. 25. 20:47반응형
메뉴 File -> New -> Other 선택 후 Spring Boot의 Spring Starter Project로 만들어준다.
프로젝트 이름, 자바 버전을 확인하고, Web Application을 만들것이기 때문에 Packaging은 War파일로 설정해두었다.
Dependencies에서 필요한 기능들을 먼저 추가할 수 있는데, pom.xml에 직접 추가하지 않아도 미리 선택해놓을 수 있다.
나는 기본적으로 devTools와 Spring Web을 추가했다.
devTools는 여러가지 기능이 있는데 캐싱이나 코드 변경시에 서버 재시작, React의 Hot Reload처럼 JS파일 수정시 브라우저가 리로드 되어서 개발할 때에 편의성을 높여준다.
이 외에도 나중에 필요한 기능이 생겼을 때는 pom.xml에 직접 dependency들을 추가하면 된다.
Spring boot 스타터 프로젝트는 기본적으로 톰캣을 가지고 있지만(spring-boot-starter-tomcat), jsp를 컴파일해주기 위해 tomcat-embed-jasper를 추가해 주었다.
프로젝트가 성공적으로 빌드되었다면 제대로 서버가 돌아가는지 확인해봐야한다.
Apache Tomcat은 webapp 디렉토리 안에 있는것들을 가져오기 때문에, webapp 폴더에 테스트용으로 index.jsp를 만들어주었다.
※원래는 보안상의 이유로 WEB-INF폴더 안에 만들어주어야 한다. 밖에 만들경우에는 모든 사용자가 인증없이 모든 애플리케이션에 액세스 할 수있다. WEB-INF 안에는 보통 web.xml, classes 폴더, lib(library) 폴더가 있다.
어쨌든 index.jsp의 body 부분에 간단한 내용만 입력을 해주었다. 이제 접속을 해야 하는데 jsp의 주소는 어떻게 될까?
일단 port를 먼저 알아야 한다. Spring Boot Web 의 기본 포트는 8080이지만, src/main/resources의 application.properties에서 간단하게 변경할 수 있다.
5001번으로 변경해주고, (사실 포트번호는 아무거나 해도 되지만 다른 애플리케이션도 고유의 port 번호를 가지고 있기 때문에 겹치게 설정하면 제대로 작동하지 않을 수 있다.)
이후에 이전의 변경사항들이 적용될 수 있게 저장해주고, 서버를 (재)시작해준다.
서버 구동은 Boot Dashboard에서 서버를 우클릭하고 (Re)start를 눌러주면 된다.
그럼 Console창에 이런 화면이 쭉 뜰텐데, 설정한 포트로 Tomcat이 구동되는 것을 확인할 수 있다.
브라우저로 localhost:5001/index.jsp에 접속했다.
성공!
참고 :
stackoverflow.com/questions/5871053/difference-between-jar-and-war-in-java
stackoverflow.com/questions/19786142/what-is-web-inf-used-for-in-a-java-ee-web-application
stackoverflow.com/questions/42154614/springboot-embedded-tomcat-and-tomcat-embed-jasper
반응형