샤인의 IT (막 적는) 메모장

[JAVA] Springboot AppApplication 실행 본문

Programming/JAVA

[JAVA] Springboot AppApplication 실행

신샤인 2022. 1. 1. 11:04
반응형

 

VSCode에서 Spring Initializer 실행하여 프로젝트를 생성한다.

 

SpringBoot - 2.6.2

Project Langauge - JAVA

Groupid - com.example

Artifactid - web

Packaging Type - jar

java version - 설치된 것

dependancy - devtool, web, postgresql, jpa

 

VSCode Spring Initializer 실행

 

 

 pom.xml에 해당 JPA dependancy 주석처리

<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.6.2</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.js</groupId>
	<artifactId>app</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>app</name>
	<description>Demo project for Spring Boot</description>
	<properties>
		<java.version>17</java.version>
	</properties>
	<dependencies>
<!--여기부분		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-data-jpa</artifactId>
		</dependency> -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-devtools</artifactId>
			<scope>runtime</scope>
			<optional>true</optional>
		</dependency>
		<dependency>
			<groupId>org.postgresql</groupId>
			<artifactId>postgresql</artifactId>
			<scope>runtime</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>

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

</project>

 

우선적으로 App 실행을 위해서 AppApplicaion에 설정

나중에 controller라는 클래스를 따로 생성할 것임

package com.js.app;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController // REST API 정의
public class AppApplication {

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

	@GetMapping // GET Request 요청
	public List<String> hello() {
		return List.of("Hello", "World!");
	}	
}

localhost:8080 실행하면 Hello World 리스트 값이 출력됨

 

반응형

'Programming > JAVA' 카테고리의 다른 글

[JAVA] Springboot Controller(API Layer) 생성  (0) 2022.01.01
[JAVA] Springboot 정보를 담는 클래스 생성  (0) 2022.01.01
[JAVA] 기본 정리  (0) 2021.12.30
[API] API란?  (0) 2021.12.30
[SpringBoot] VSCode 개발환경 구성  (0) 2021.12.30
Comments