본문 바로가기

[spring boot] 웹개발을 위한 기본 라이브러리

I'm 영서 2024. 7. 10.
반응형

 

기본적으로 웹 개발을 함에 있어 가장 간편한 방법 중 하나는 

http://start.spring.io

에서 시작하는 방법이라고 생각한다.

 

 

기본적으로 나는 Maven, Java를 선호하는데, 아무튼 Project 부분은 프로젝트의 빌드 도구를 정하는 방법인데, 

Gradle 을 사용할지 (그중에 Groovy, Kotlin 이 있다.) Maven을 사용할지에 대해 결정할 수 있다.

 

Gradle

build.gradle 파일을 통해 구성되며, 플러그인, 의존성, 태스크 등의 정의를 하고, 프로젝트를 빌드하면 프로젝트 구조 파악, 태스크 그래프구성 및 의존성 정의, 실행 단계를 거친다.

 

같은 구성요소에 대해 각기 표현방식을 확인해보자. 

더보기

Groovy

plugins {
    id 'java'
    id 'application'
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'com.google.guava:guava:30.1.1-jre'
    testImplementation 'junit:junit:4.13.2'
}

application {
    mainClassName = 'com.example.Main'
}

task customTask {
    doLast {
        println 'This is a custom task.'
    }
}

 

Kotlin 

plugins {
    java
    application
}

repositories {
    mavenCentral()
}

dependencies {
    implementation("com.google.guava:guava:30.1.1-jre")
    testImplementation("junit:junit:4.13.2")
}

application {
    mainClass.set("com.example.Main")
}

tasks.register("customTask") {
    doLast {
        println("This is a custom task.")
    }
}

 

Maven

<project xmlns="http://maven.apache.org/POM/4.0.0" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>example-app</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <mainClass>com.example.Main</mainClass>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>30.1.1-jre</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13.2</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>${maven.compiler.source}</source>
                    <target>${maven.compiler.target}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.1.2</version>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>${mainClass}</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.6.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>java</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <mainClass>${mainClass}</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

 

셋이 똑같은 말 하는거다.. 

 

아무튼 Project 빌드 방식, 언어를 선택 한 후 Dependency를 골라야한다.

 

기본적으로 선택해야 할 것 (추천)

필수 라이브러리

Spring Boot DevTools Spring 개발 도구 Tools  
Spring Web 웹 개발 기본 라이브러리  
Spring Data JPA 데이터베이스 접근을 위한 라이브러리  
MySql Driver MySQL사용을 위한 라이브러리 나같은 경우 Mysql을 사용하기 때문에 해당 라이브러리를 추가했다. (안쓸거면 필요 X)
Spring Security 사용자 인증 회원 관리를 할 예정이라 추가하였음
선택 라이브러리
OAuth2 Client 소셜 로그인 구현을 위한 라이브러리  
Thymeleaf 템플릿 엔진(프론트 엔드용) 
Spring에서 권장한다.
LomBok 코드 간결화 Setter, Getter등의 불편함을 줄여준다.

 

이정도로 설정 후 Generate를 누르면 압축파일이 생성된다.

 

압축파일을 workspace에 풀고 개발 도구로 열면 프로젝트 생성은 끝. 

 

만약 security를 넣지 않았다면 실행해도 바로 될것이다. 

반응형

댓글