728x90
스프링 공식 홈페이지
The @SpringBootApplication Annotation
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan(
excludeFilters = {@Filter(
type = FilterType.CUSTOM,
classes = {TypeExcludeFilter.class}
), @Filter(
type = FilterType.CUSTOM,
classes = {AutoConfigurationExcludeFilter.class}
)}
)
public @interface SpringBootApplication {
SpringBootApplication 어노테이션에는 다음과 같은 어노테이션을 포함한다.
- SpringBootConfiguration
- EnableAutoCOnfiguration
- ComponentScan
이 중 @EnableAutoConfiguration은 추가한 jar 종속성을 바탕으로 스프링을 구성하는 방법을 "추측"하라고 알려준다.
스프링 부트 시작하는 방법
스프링부트 공식 홈페이지 레퍼런스에서는 만든 애플리케이션을 실행하기 위해 다음과 같은 명령줄을 제공한다.
$ gradle bootRun
각자의 컴퓨터 운영체제와 gradle 버전을 다운로드 받지 않았을 경우에는 실행할 수 없다. (인식하지 못한다.)
이 때 프로젝트 내에 Gradle Wrapper
를 제공하는데, gradlew
을 통해서 별도로 설치하지 않고 프로젝트에서 바로 실행할 수 있도록 도와준다.
- 프로젝트 루트 디렉터리 이동
- 다음 명령어 실행
./gradlew bootRun
윈도우 환경에서는 gradlew.bat
을 사용해야할 수 도 있다.
.\gradlew bootRun
> Task :bootRun
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v3.4.1)
2024-12-28T16:43:13.691+09:00 INFO 2600 --- [firstboot] [ main] c.e.firstboot.FirstbootApplication : Starting FirstbootApplication using Java 17.0.11 with PID 2600 (C:\lect_springfw\spring\firstboot\build\classes\java\main started by 9712jw in C:\lect_springfw\spring\firstboot)
2024-12-28T16:43:13.695+09:00 INFO 2600 --- [firstboot] [ main] c.e.firstboot.FirstbootApplication : No active profile set, falling back to 1 default profile: "default"
2024-12-28T16:43:14.560+09:00 INFO 2600 --- [firstboot] [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port 8080 (http)
2024-12-28T16:43:14.574+09:00 INFO 2600 --- [firstboot] [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2024-12-28T16:43:14.574+09:00 INFO 2600 --- [firstboot] [ main] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.34]
2024-12-28T16:43:14.626+09:00 INFO 2600 --- [firstboot] [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2024-12-28T16:43:14.627+09:00 INFO 2600 --- [firstboot] [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 888 ms
2024-12-28T16:43:14.923+09:00 INFO 2600 --- [firstboot] [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port 8080 (http) with context path '/'
2024-12-28T16:43:14.928+09:00 INFO 2600 --- [firstboot] [ main] c.e.firstboot.FirstbootApplication : Started FirstbootApplication in 1.561 seconds (process running for 1.882)
<==========---> 80% EXECUTING [17s]
> :bootRun
실행 가능한 jar 생성
실행 가능한 jar 만들려면 다음과 같이 명령줄에서 dradle bootjar를 실행합니다.
$ gradle bootJar
BUILD SUCCESSFUL in ...
3 actionable tasks : 3 e...
build/libs 디렉터리를 보면 내 <project-name>-0.0.1-SNAPSHOT.jar
파일이 생성된다.
만약 내부를 보고 싶다면 다음과 같은 명령줄을 입력한다.
$ jar tvf build/libs/myProject-0.0.1-SNAPSHOT.jar
만들어진 jar 파일을 실행시키기 위해서 java -jar
명령을 입력한다.
java -jar build/libs/myProject-0.0.1-SNAPSHOT.jar
$ java -jar build/libs/myproject-0.0.1-SNAPSHOT.jar
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v{version-spring-boot})
....... . . .
....... . . . (log output here)
....... . . .
........ Started MyApplication in 0.999 seconds (process running for 1.253)