SpringBoot으로 웹 출시까지 #1

springboot logo

1. 환경설정

1 chocolatey 다운로드

JAVA를 다운받기 위해 JAVA 관리 도구로 chocolatey를 다운받는다.

chocolatey로 다운 받으면 따로 환경설정을 할 필요가 없어 간편하게 관리 할 수 있다.

 

https://chocolatey.org/install

에 들어가서 명령어를 복사한다.

 

2023.02.21 기준 명령어는 다음과 같다.

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString(‘https://community.chocolatey.org/install.ps1’))

 

 

– powershell을 “관리자 권한“으로 열어 복사한 명령어를 입력한다.

– 입력한 명령어대로 설치가 잘 되고 있는지 확인한다.

 

 

– 명령어 입력 후 cmd를 “관리자 권한“으로 실행한다.

– “choco -version”을 입력해 설치를 확인한다.

 

 

– 강의와 choco 버전이 다른 것은 문제가 되지 않는다.

– 설치가 되지 않았다면 높은 확률로 관리자 권한으로 열지 않은 것이다.

– 빨간 오류로 당황스러워 여러 시도를 했는데 단순히 관리자 권한으로 열어서 덮어 쓰는 것이 정답이었다.

2 openjdk 설치

– https://community.chocolatey.org/packages?q=openjdk+8 에서

“choco install openjdk8” 명령어를 복사한다.

– cmd 또는 powershell을 “관리자모드”로 열어서 명령어를 입력한다.

설치 도중 긴 말이 나온다면 설치를 허락하겠다는 yes all의 의미로 a를 입력한다.

 

혹시 이전에 자바를 다운받으셨고, 환경설정을 완료하셨다면 제어판 자바 환경설정을 삭제하시는 것을 권장드린다.

choco가 자동으로 환경설정을 해주기 때문에 충돌의 우려가 있다.

3 maven 설치

 https://community.chocolatey.org/packages?q=maven 에서

“choco install maven” 명령어를 복사한다.

– cmd 또는 powershell을 “관리자모드”로 열어서 명령어를 입력한다.

설치 도중 긴 말이 나온다면 설치를 허락하겠다는 yes all의 의미로 a를 입력한다.

 

동영상과 메이븐의 버전이 다르더라도 문제가 없다.

4 IntelliJ 다운로드

https://www.jetbrains.com/ko-kr/idea/download/#section=windows

community edition을 다운받아 설치한다.

5 IntelliJ 설정 및 myjava 만들어 실행 확인하기

동영상 보고 따라하기

public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}

6 myrest 만들어서 restful web 동작 확인

동영상 보고 따라하기

https://start.spring.io/

 

project : maven

springboot :  최대한 낮은 버전 / SNAPSHOT X로 선택

group :  com.godcoder

artifact, name : myrest

java: 8

dependencies : Spring Web

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
package com.godcoder.myrest;

public class Greeting {
private final long id;
private final String content;

public Greeting(long id, String content){
this.id = id;
this.content = content;
}

public long getId(){
return id;
}
public String getContent(){
return content;
}

}
package com.godcoder.myrest;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.atomic.AtomicLong;

@RestController
public class GreetingController {

private static final String template = "Hello, %s!";
private final AtomicLong counter = new AtomicLong();

@GetMapping("/greeting")
public Greeting greeting(@RequestParam(value = "name", defaultValue = "World") String name) {
return new Greeting(counter.incrementAndGet(), String.format(template, name));
}
}

http://localhost:8080/greeting

*오류 방지

– 만들어진 maven 프로젝트를 열었을 때

com.godcoder.myrest 로 표시되지 되지 않는다면 파일을 잘못열었거나 이전에 설정을 잘못하신겁니다.

설정을 잘못했을리가 없으시다면 파일을 삭제하고 다시 다운받아 여시는 것을 추천합니다.


– 파일을 추가하실 때 바로 java 클래스 추가가 뜨지 않거나

– 클래스 이름 옆 표시가 파란색이 아니라면 오류가 발생한 것입니다.

오류 코드를 보고 수정이 필요합니다.

– maven 프로젝트를 실행하는 방법은

두 개의 초록색 세모를 누르시면 됩니다.

위의 세모를 누르면 자동으로 실행됩니다.

혹시 오류가 발생했다면 잠시 쉬었다가 재실행 시키시는 것을 추천드립니다.


“Web server failed to start. Port 8080 was already in use.” 가 발생하셨다면 인텔리제이를 껐다가 다시 실행시키시면 바로 해결됩니다.

“SpringBoot으로 웹 출시까지 #1”의 338개의 댓글

  1. I blog quite often and I genuinely thank you for your information. Your article has really
    peaked my interest. I’m going to book mark your website and
    keep checking for new details about once a week.
    I opted in for your RSS feed too.

  2. Pretty section of content. I just stumbled upon your blog and
    in accession capital to assert that I get
    in fact enjoyed account your blog posts. Anyway I’ll be subscribing to your
    augment and even I achievement you access consistently quickly.

  3. If you’re planning to adopt a child, the fees can be substantial and often require payment upfront.
    An installment loan can help you cover those costs without
    draining your savings. The lenders listed on Piggy Advance offer large loan amounts with reasonable rates.

  4. I’m extremely impressed with your writing skills and also with the layout
    on your weblog. Is this a paid theme or did you modify it yourself?
    Either way keep up the excellent quality writing, it’s rare to see a nice blog like this one nowadays.

댓글 달기

이메일 주소는 공개되지 않습니다.