이전에 스프링 프로젝트를 진행해봤음에도 초기 세팅은 어렵다.
인프런을 들으며 하나씩 정리하며 들어보는Spring프로젝트 초기세팅
spring.io
에 들어가서 프로젝트를 만든다.Gradle
Spring Boot : 2.7.9
(* 3점대는 java버전 17부터 가능하다. 나는 11을 쓰기 때문에 2점대로 설정)
Dependencies
를 추가한다.
Spring Web
, Thymeleaf
, JPA
, H2 DB
, Lombok
generate
을 눌러 원하는 위치에 다운받는다.intelliJ를 열고 import
나 open
을 누르고, 다운받은 파일 위치에서 Build.gradle
을 연다.
설치가 완료되면 끝!
( 설치가 진행되는 동안엔 기다려야한다.)
intelliJ
에선 처음이라 검색을 통해 알았다.
- 깃 설치 확인
git --version
- 나는 깃을 설치했고, 인텔리제이에 깃 계정을 등록해 놓았었다.
command+,
에서 Git - Path to Git executable을 확인.Test
를 눌러 테스트.clone
을 하거나 Git -> GitHub -> Share Project on GitHub
를 한다.Share Project on GitHub
를 했다.처음에
JUnit4 추가
를 하고 돌렸는데 났다.추가📌
에러 이유 :dependencies{}
아네 JUnit4를 넣어야 했다.
괄호 밖에 넣어서 에러났던것이다.
//JUnit4 추가 testImplementation("org.junit.vintage:junit-vintage-engine") {
exclude group: "org.hamcrest", module: "hamcrest-core"
}
A problem occurred evaluating root project 'jpashop'. > Could not find method testImplementation() for arguments
방법을 못찾다가, 인프런 자료를 보고 해결하였다.
아래처럼IntelliJ IDEA
로 변경했더니 돌아간다.
-참고: 강의에 이후에 추가된 내용입니다.
Preferences - Build, Execution, Deployment - Build Tools - Gradle
IntelliJ IDEA
IntelliJ IDEA
JpashopApplication
command + ,
- Annotation Processors
- Enable annotation processing 에 체크Hello
클래스를 만들고 Getter
, Setter
package jpabook.jpashop;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class Hello {
private String data;
}
Main
으로 가서 입력hello.getData();
입력 후 option + command + v
를 누르면 String data = hello.getData();
이렇게 된다package jpabook.jpashop;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class JpashopApplication {
public static void main(String[] args) {
Hello hello = new Hello();
hello.setData("hello");
String data = hello.getData();
System.out.println("data = " + data);
SpringApplication.run(JpashopApplication.class, args);
}
}
실행하면 아래처럼 확인할 수 있다.