(1)IntelliJ & SpringBoots

로쿠's avatar
Aug 28, 2024
(1)IntelliJ & SpringBoots

1-1. IntelliJ 다운

 
들어가서 밑으로 내려보면
notion image
다운 받기.
설치 시 java 하고 옆에 두 가지 체크 해주고 나머지는 다 next 누르면 끝
 

1-2. jdk 21 다운

여기 들어가서 21 다운로드 해주기.
notion image

1-3. 폴더 만들어주기

새로운 폴더 안에 3가지 만들기.
notion image
javawork 는 java로 만든 소스코드 파일
springwork는 spring 프레임워크로 만든 소스코드 파일
tools 는 개발 환경에 필요한 도구들 ex) jdk
 

2. Springboots

2-1 환경설정

 
https://start.spring.io/ 에 들어가서 시작
  • 추세는 Maven이 아닌 Gradle
notion image
 
GENERATE 클릭하면 알집이 다운 된다.
알집을 풀고 java work안에 폴더 넣어주기.
 
notion image
 
인텔리제이에 프로젝트에 오픈 체크하고 그 후에 java work 폴더 안에 있는 helloSpring 폴더 클릭하면 사용할 수 있다.
notion image
HelloSpringApplication에서
notion image
main을 실행시키고
notion image
localhost:8080 을 입력하면 에러페이지가 뜬다.(제대로 설치되어 있다는 걸 확인 = 프로젝트 환경설정을 했다는 뜻)
요즘은 테스트까지 자동으로 만들어준다 = 그만큼 테스트가 중요해졌다는 뜻이기도 하다.
 
*번외
notion image
설정에서 gradle을 쳐서 보면 Build랑 Run 이 Gradle이다.
간혹 gradle에서 작동하면 느려지는 경우가 있기 때문에 IntelliJ로 바꿔주는 것이 속도 측면에서 좋다.

2-2 라이브러리

 
notion image
Maven 이나 Gradle은 요새 의존 관계를 다 관리해준다.
notion image
우리가 필요한 건 starter-web이지만, 알아서 필요한 것들을 다 땡겨온다.
notion image
notion image
톰캣을 포함 스프링 코어까지 다 가져온다.
 
로깅 : 취업시 sout가 아닌 로그로 남겨야 기록에 다 남는다.
notion image
스프링부트 쓰면 다 들어옴.
 

2-3 View 환경설정

 
welcome page 만들어주기
1) static 에 new file 만들어주기.
notion image
2) 코드 입력
notion image
3) 만약 인코딩이 UTF-8 이 아니라면 들어가서 설정 바꿔주기.
notion image
적용 유무는 우측 하단에서 확인할 수 있다.
notion image
 
여기까지는 정적페이지 = 파일을 그냥 던져줌
 
thymeleaf 템플릿 엔진을 쓰면 서버에서 동적으로 데이터를 처리하여 HTML 파일에 데이터를 삽입한 후 그 결과를 클라이언트에게 전달한다.
1) controller 패키지를 추가한 후 그 안에 HelloController java 파일로 만들어주기.
notion image
notion image
2) resources > templates > hello.html 생성new file로 만들어 주면 된다.
*spring-boot-devtools 라이브러리를 추가시 .html 파일을 컴파일만 하면 서버 재시작을 안하고도 View 파일 변경이 가능하다.
notion image
+)추가방법
1) build.gradle 에 dependencies 에 의존성 추가
notion image
2) resources > applecation.properties 파일에 사용 여부를 추가하여 사용할 땐 true, 사용하지 않을 때는 false로 바꾸어 유동적으로 사용할 수 있다.
3) File > Settings >  Build, Exeution, Deployment > Compiler > Build project autiomaically 체크
notion image
File > Settings > Advanced Settings > Compiler > Allow auto-make to strat even if developed application is currently running 체크
notion image

2-4. 빌드하고 실행하기

 
notion image
helloSpring 폴더에서 cmd 실행 후 gradlew.bat build 입력
필요한 파일이 있다면 다운로드 혹은 생성이 된다.
notion image
그 다음 cd build/libs 를 통하여 build 되어있는 Directory 로 이동
notion image
그 후에 java -jar helloSpring-0.0.1-SNAPSHOT.jar 를 입력해주면 된다.
 
 
Share article