Spring boot 실행 후 바로 종료될 때

jong·2022년 8월 23일
0

SpringBoot

목록 보기
1/4

스프링 부트 프로젝트를 https://start.spring.io/ 혹은 인텔리제이에서 생성한 직후에 프로젝트를 실행하면 아래와 같이 시작하자마자 종료되는 현상이 있다.

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::       (v2.7.4-SNAPSHOT)

2022-08-23 15:07:03.608  INFO 27719 --- [           main] i.g.potatoy.Application     : Starting Application using Java 11.0.15
2022-08-23 15:07:03.609  INFO 27719 --- [           main] i.g.potatoy.Application     : No active profile set, falling back to 1 default profile: "default"
2022-08-23 15:07:03.880  INFO 27719 --- [           main] i.g.potatoy.Application     : Started Application in 0.443 seconds (JVM running for 1.175)

Process finished with exit code 0

이럴 때에는 아래와 같이 수정하면 된다.

기존 build.gradle

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

추가할 내용

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

spring-boot-starter-web을 추가하면 스프링 부트 프로젝트에 필요한 대부분의 라이브러리가 추가된다.

그리고 main class@EnableWebMvc를 추가한다. @EnableWebMvc annotation을 추가함으로써 Spring Framework에서 여러 Config 값을 알아서 세팅해준다.

@EnableWebMvc
@SpringBootApplication
public class Application {

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

}

다만 필자의 경우 해당 어노테이션을 추가할 경우 static/index.html에 접근할 수 없었다.

관련 내용
https://smelting.tistory.com/51
https://goodgid.github.io/Spring-Enable-MVC-Annotation/

profile
공부 기록

0개의 댓글