[프로젝트 환경 설정] 스프링 입문 - 코드로 배우는 스프링 부트
어플 개발 프로젝트를 진행하면서 프론트만 담당했던 내가 crud를 처리할 수 있는 백엔드의 지식이 필요했다.
백엔드의 'ㅂ' 조차 모르지만 인프런 강의를 시작으로 '백'을 알기 위해 공부해보려한다.
그리고 그것을 블로그에 남기려고 한다.
내가 듣고 있는 강의는 김영환님의 스프링 입문 강의이다. 일단 무료기도 하고 입문이라는 단어가 붙어있어 안심하고 들을 수 있다는 생각을 했다. 대부분의 스프링 강의는 스프링에 대해 어느정도 알고 있어야 하기 때문이다.
[무료] 스프링 입문 - 코드로 배우는 스프링 부트, 웹 MVC, DB 접근 기술 - 인프런 | 강의
스프링 입문자가 예제를 만들어가면서 스프링 웹 애플리케이션 개발 전반을 빠르게 학습할 수 있습니다., - 강의 소개 | 인프런...
www.inflearn.com
이곳은 spring initializr 로 기본 spring 프로젝트를 생성할 수 있는 곳이다.
dependencies는 스프링 부트에서 제공하는 의존성 관리 기능이다.
add dependecies 는 스프링부트에서 어떤 라이브러리를 쓸건지 고르는 것이다.
web, thymeleaf 를 추가했다.
thymeleaf는 html을 만들어 주는 템플릿 엔진이다.
generate하여 얻은 zip파일을 인텔리제이 폴더로 연다.
처음에 열면 build.gradle 파일이 인식이 되지 않아 회색으로 뜰 수 있다. 그 때는 .idea 파일을 지우고 인텔리제이를 재부팅한다.
실행 시키고 execution failed for task ':compilejava'. 이런 에러가 나면 자바의 버전이 맞지 않는 것이다.
build.gradle 파일에 가면 자신의 자바 버전이 11이라는 것을 알 수 있다.
File -> Project structure -> Platform settings -> SDKs
에 들어가서 플러스 버튼을 누르면 Download JDK를 해서 인텔리제이 내부에서 jdk를 다운받을 수 있다.
File -> Settings 에 가서
이 두 개를 바꿔야 한다. 그럼 정상적으로 실행이 될 것이다.
실행 시키면 이런게 나온다.
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.6.4)
2022-03-17 23:34:16.905 INFO 6948 --- [ main] h.hellospring.HelloSpringApplication : Starting HelloSpringApplication using Java 11.0.14.1 on DESKTOP-A7JSAIN with PID 6948 (C:\Users\User\IdeaProjects\hello-spring\hello-spring\out\production\classes started by User in C:\Users\User\IdeaProjects\hello-spring)
2022-03-17 23:34:16.908 INFO 6948 --- [ main] h.hellospring.HelloSpringApplication : No active profile set, falling back to 1 default profile: "default"
2022-03-17 23:34:17.965 INFO 6948 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-03-17 23:34:17.979 INFO 6948 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-03-17 23:34:17.980 INFO 6948 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.58]
2022-03-17 23:34:18.070 INFO 6948 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-03-17 23:34:18.070 INFO 6948 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1096 ms
2022-03-17 23:34:18.392 WARN 6948 --- [ main] ion$DefaultTemplateResolverConfiguration : Cannot find template location: classpath:/templates/ (please add some templates or check your Thymeleaf configuration)
2022-03-17 23:34:18.466 INFO 6948 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2022-03-17 23:34:18.477 INFO 6948 --- [ main] h.hellospring.HelloSpringApplication : Started HelloSpringApplication in 2.136 seconds (JVM running for 2.652)
localhost:8080 에 들어가면 이런 에러 페이지가 나온다.
그럼 잘 된 것!
프로젝트가 gradle을 통해 실행되면 느려지기 때문에 Build and run using 과 Run test using을 모두 Intellij IDEA 로 변경한다.