Super Kawaii Cute Cat Kaoani
본문 바로가기
⚙️ Back-end/SpringBoot

Springboot [1] : 환경설정 및 예제

by wonee1 2024. 3. 2.
728x90

* 책 스프링부트 3 백엔드 개발자 되기 자바편을 공부하면서 정리한 내용입니다
 
 
 

스프링부트 프로젝트 생성 

 

plugins {
    id 'java'
    id 'org.springframework.boot' version '3.0.2'
    id 'io.spring.dependency-management' version '1.1.0'
}

group = 'me.shinsunyoung'
version = '1.0-SNAPSHOT'
sourceCompatibility = '17'


repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

test {
    useJUnitPlatform()
}

build.gradle 설정
 

  • plugins에는 프로젝트에 사용할 플러그인인 스프링 부트 플러그인 org.springframework.boot가 있음
  • 스프링의 의존성을 자동으로 관리하는 spring.dependency-management도 추가함
  • group에 프로젝트를 설정할 때의 기본값인  그룹 이름과 버전이 있음
  • repositories에는 의존성을 받을 저장소를 지정

 
 
 

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;


@SpringBootApplication
public class SpringBootDeveloperApplication {
    public static void main(String[] args) {
        SpringApplication.run(SpringBootDeveloperApplication.class, args);
    }
}

springBootDeveloperApplication.java 설정
 
 
 
 
☑️ 이 두 코드를 작성한 다음  다음 실행을 하였을 때 이러한 오류가 발생하였다. 
 

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0. You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins. For more on this, please refer to https://docs.gradle.org/8.4/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation. BUILD FAILED in 2s 2 actionable tasks: 1 executed, 1 up-to-date

 
📌책을 보고 선택값 gradle(default)를 intellij idea로 바꿔 다시 실행하니 해결되었다.
 
 
 


 
 
 
 
☑️ 교재 54쪽에서 55쪽의 예제를 책 그대로 똑같이 실행해주었는데 localhost가 실행되지 않는 오류가 계속해서 발생했다. 
 

 

발생한 오류

 
포트 8080을 다른 프로그램이 사용하고 있어서 발생한 오류였다. 
 
 

 
 
📌 resources에 application.properties파일을 추가하여 포트번호를 8081로 변경하였더니 해결되었다
 
 
 
 

다시 실행한 결과

성공적으로 출력되었다. 
 
 

자바 애너테이션 

 
자바 애너테이션이란?
 
자바로 작성한 코드에 추가하는 표식 
다양한 목적으로 사용하지만 보통은 메타 데이터로 사용하는 경우가 많다 
 

애너테이션 이름  설명 
@Override 선언된 메서드가 오버라이드 되었음
@Depercated 더 이상 사용되지 않음
@SuppessWarnings 컴파일 경고를 무시함 

 
 

public class A extends B{

	@Override // 선언된 메서드가 오버라이드 되었음을 나타내는 애너테이션
    public void print(){
       System.out.println("Hello, World");
      }
  
  }
728x90