대충이라도 하자

Spring Boot Tutorial | Full Course [2021] (2) 본문

꼬꼬마 개발자 노트/Spring

Spring Boot Tutorial | Full Course [2021] (2)

Sueeeeee
반응형

1. spring initializer로 스프링부트 생성하기

- 빌드 도구 : Maven

- 언어 : 자바

- Packaging은 jar로 : godaddy는 jar파일을 지원하지 않으므로 war 패키징 선택해야 함

- 추가 dependency : spring web / Spring data JPA / PostgreSQL Driver

- IDE : IntelliJ

2. IntelliJ에서 열고 빌드 해줍니다.

그런 다음, Main -> Application 클래스를 run해주면 아래와 같은 오류(?)가 발생

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class

Action:

Consider the following:

If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.

If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

*** 다시 프로젝트 만들려고 새로 생성하니, 이렇게 나와서 너무 당황했는데 아무 설정 없으면 원래 나오는 거였구나....

아래와 같이 pom.xml 파일의 JPA dependency 부분을 주석 처리해주고 maven -> reload project 해주면 됨.

<!-- <dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-data-jpa</artifactId>

</dependency>-->

3. Application 클래스에 추가해서 'localhost:8080'이 작동하게 만들어주기

- 첫번째로 클래스에 @RestController 달아주기

아래의 사진 설명에도 있지만 이는 아래의 클래스가 restful endpoint를 수행하게끔 만들어준다.

- 두 번째로 public String hello() 라는 메소드를 추가한 뒤, @GetMapping 추가

함수가 작동하기 위해 restful endpoint로 사용되기 위한 annotation 해주기

4. Json data로 던져주려면?

5. 다음은 아래 그림처럼 던져줄 거임!

반응형
Comments