ⓦeb ⓢtory/Spring

[SpringBoot] QuickStart

뚱땡이 우주인 2018. 3. 10. 17:55

$ mvn -B archetype:generate -DgroupId=com.example -DartifactId=hajiboot -Dversion=1.0.0-SNAPSHOT -DarchetypeArtifactId=maven-archetype-quickstart


app.java

package com.example;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* Hello world!
*
*/

@RestController // 이 클래스가 웹 애플리케이션에서 요청(request)을 받아들이는 컨트롤 클래스임을 나타냄
@EnableAutoConfiguration // 다양한 설정이 자동으로 수행되고 기존의 스프링 애플리케이션에서 필요했던 설정 파일들이 필요 없어짐
public class App
{
@RequestMapping("/") // 메서드가 HTTP요청을 받아들이는 메서드임을 나타냄
String home() {
return "Hello World!!!"; // HTTP 응답을 반환
}
public static void main( String[] args )
{
// 스피링 부트 애플리케이션을 실행하는데 필요한 처리
// @EnableAutoConfiguration 가 붙은 클래스를 첫번째 인자로 지정
SpringApplication.run(App.class, args);
}
}



pom.xml

<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>hajiboot</artifactId>
<packaging>jar</packaging>
<version>1.0.0-SNAPSHOT</version>
<name>hajiboot</name>
<url>http://maven.apache.org</url>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
</parent>

<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.0.0.RELEASE</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.0.0.RELEASE</version>
</plugin>
</plugins>
</build>

<properties>
<java.version>1.8</java.version>
</properties>
</project>




src/main/resources/application.properties

server.port=8888


$ mvn spring-boot:run


open browser with localhost:8888