Spring boot로 포트폴리오 작업하기

2022. 5. 18. 12:50카테고리 없음

포트폴리오를 pdf로 만들려다가 너무 없어보여서 bootstrap 템플릿 가져다가 뜯어고쳐서 만들기로 했다..

github.io로 블로그 만들고 거기에 포트폴리오 페이지를 올리려는데 바로바로 확인을 못하니깐

sts에서 새 프로젝트를 만들어서 하기로 했다.

고생이 여기서 시작되었다... 이클립스 업데이트가 화근이었음..

톰캣 설정을 잘못했는지 하도 에러가 떠서......

함부로 업데이트하는거 아니구나.......

 

이클립스, 자바, 톰캣, sts 싹 다 지우고

자바, 톰캣, sts 재설치했다..

sts를 이클립스 기반인걸 받아서 굳이 이클립스를 또 깔지 않았다.

sts를 boot 주력인 4버젼으로 깔고...(미래를 위해..) eclipse marketplace에서 sts3 (기존 spring mvc 등을 위해...), eclipse web developer tool 등등 다 install 하고..

 

web project에서 static, dynamic, spring legacy 다 시도해봤는데 자꾸 서버가 안뜨거나 연결이 거부되거나 했다.

그렇다고 익숙한 spring mvc를 새로 만들자니.. 설정 언제 또 다 해...? 어차피 static 만드는데..?

그러다가 spring.io 공홈에서 본 엄청 간단한 boot 시작 guide가 생각났다.

설정이고 뭐고 별로없고 tomcat도 내장되어있고 static만 할거니깐.. 간단하겠지?

그래서 sts에서도 아예 시도해보라고 있는 spring boot - spring starter project로 만들었다.

설정에 뭘 넣을까하다가 web 정도만 넣고..

역시.. 도전을 두려워하기보다 그냥 막 시도해봐야한다!!!

port 8080 가 already in use 라길래 구글링해서 cmd에서 kill pid 이런것도 해봤는데 내 컴은 안죽이겠다고 반항을 했다.

그래서 구글링 또 해서 찾아냄

https://www.baeldung.com/spring-boot-change-port 

 

How to Change the Default Port in Spring Boot | Baeldung

Have a look at how you can change the default port in a Spring Boot application.

www.baeldung.com

가끔씩 도움받는 기초지식의 도우미 baeldung 아저씨가 포트번호 바꾸기 설정을 application.properties 에다가 해주래서 써줬더니 성공~~

spring.io에서 알려준대로 localhost:{내포트번호}/hello 들어갔더니 잘 떴다.

 

이제 템플릿에서 가져온 static 파일들을 어디에 넣어야하고 java파일엔 어떻게 써줄지! 

아래 주소 참고했다. 
https://spring.io/guides/gs/serving-web-content/#_add_a_home_page

 

Serving Web Content with Spring MVC

this guide is designed to get you productive as quickly as possible and using the latest Spring project releases and techniques as recommended by the Spring team

spring.io

위의 것들은 스르륵 읽고 add a home page 파트에 보니깐 index.html이랑 static 파일들은 /static 에다가 넣으란다.

 

Static resources, including HTML and JavaScript and CSS, can be served from your Spring Boot application by dropping them into the right place in the source code. By default, Spring Boot serves static content from resources in the classpath at /static (or /public). The index.html resource is special because, if it exists, it is used as a "`welcome page,"serving-web-content/ which means it is served up as the root resource (that is, at `http://localhost:8080/

 

다크모드에서 복붙하니깐 이렇게 되네~~ 하라는대로 하니깐 잘 작동된다!

이제 수정만 하면 된다 ㅠㅠ 신난다~~~~~~~~~~~