Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/harryjhin/hello-springboot
간단한 Spring Boot 애플리케이션
https://github.com/harryjhin/hello-springboot
Last synced: about 1 month ago
JSON representation
간단한 Spring Boot 애플리케이션
- Host: GitHub
- URL: https://github.com/harryjhin/hello-springboot
- Owner: HarryJhin
- Created: 2022-05-09T05:07:08.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-05-09T05:37:53.000Z (over 2 years ago)
- Last Synced: 2023-12-25T03:24:02.803Z (12 months ago)
- Language: Java
- Size: 66.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Spring Boot Hello Example
### 개요
Spring Boot를 사용하여 간단한 웹 애플리케이션을 빌드하고, 몇 가지 유용한 서비스를 추가합니다.
### 애플리케이션 실행
애플리케이션을 실행하려면 터미널 창에서 프로젝트의 루트 디렉토리로 이동하고 다음 명령을 실행합니다.
```shell
./gradlew bootRun
```Maven을 사용할 경우:
```shell
./mvnw spring-boot:run
```#### 실행 결과
```shell
'Spring'에서 제공하는 'Bean'에 대해 알아보자:
applicationAvailability
applicationTaskExecutor
basicErrorController
beanNameHandlerMapping
beanNameViewResolver
characterEncodingFilter
commandLineRunner
conventionErrorViewResolver
defaultServletHandlerMapping
defaultViewResolver
dispatcherServlet
dispatcherServletRegistration
error
errorAttributes
errorPageCustomizer
errorPageRegistrarBeanPostProcessor
flashMapManager
forceAutoProxyCreatorToUseClassProxying
formContentFilter
handlerExceptionResolver
handlerFunctionAdapter
helloApplication
helloController
httpRequestHandlerAdapter
jacksonObjectMapper
jacksonObjectMapperBuilder
jsonComponentModule
lifecycleProcessor
localeCharsetMappingsCustomizer
localeResolver
mappingJackson2HttpMessageConverter
messageConverters
multipartConfigElement
multipartResolver
mvcContentNegotiationManager
mvcConversionService
mvcHandlerMappingIntrospector
mvcPathMatcher
mvcPatternParser
mvcResourceUrlProvider
mvcUriComponentsContributor
mvcUrlPathHelper
mvcValidator
mvcViewResolver
org.springframework.aop.config.internalAutoProxyCreator
org.springframework.boot.autoconfigure.AutoConfigurationPackages
org.springframework.boot.autoconfigure.aop.AopAutoConfiguration
org.springframework.boot.autoconfigure.aop.AopAutoConfiguration$ClassProxyingConfiguration
org.springframework.boot.autoconfigure.availability.ApplicationAvailabilityAutoConfiguration
org.springframework.boot.autoconfigure.context.ConfigurationPropertiesAutoConfiguration
org.springframework.boot.autoconfigure.context.LifecycleAutoConfiguration
org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration
org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration
org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration$StringHttpMessageConverterConfiguration
org.springframework.boot.autoconfigure.http.JacksonHttpMessageConvertersConfiguration
org.springframework.boot.autoconfigure.http.JacksonHttpMessageConvertersConfiguration$MappingJackson2HttpMessageConverterConfiguration
org.springframework.boot.autoconfigure.info.ProjectInfoAutoConfiguration
org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory
org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration
org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$Jackson2ObjectMapperBuilderCustomizerConfiguration
org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$JacksonObjectMapperBuilderConfiguration
org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$JacksonObjectMapperConfiguration
org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$ParameterNamesModuleConfiguration
org.springframework.boot.autoconfigure.sql.init.SqlInitializationAutoConfiguration
org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration
org.springframework.boot.autoconfigure.task.TaskSchedulingAutoConfiguration
org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration
org.springframework.boot.autoconfigure.web.embedded.EmbeddedWebServerFactoryCustomizerAutoConfiguration
org.springframework.boot.autoconfigure.web.embedded.EmbeddedWebServerFactoryCustomizerAutoConfiguration$TomcatWebServerFactoryCustomizerConfiguration
org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration
org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration$DispatcherServletConfiguration
org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration$DispatcherServletRegistrationConfiguration
org.springframework.boot.autoconfigure.web.servlet.HttpEncodingAutoConfiguration
org.springframework.boot.autoconfigure.web.servlet.MultipartAutoConfiguration
org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration
org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryConfiguration$EmbeddedTomcat
org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration
org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration
org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter
org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration
org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration$DefaultErrorViewResolverConfiguration
org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration
org.springframework.boot.autoconfigure.websocket.servlet.WebSocketServletAutoConfiguration
org.springframework.boot.autoconfigure.websocket.servlet.WebSocketServletAutoConfiguration$TomcatWebSocketConfiguration
org.springframework.boot.context.internalConfigurationPropertiesBinder
org.springframework.boot.context.internalConfigurationPropertiesBinderFactory
org.springframework.boot.context.properties.BoundConfigurationProperties
org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor
org.springframework.boot.context.properties.EnableConfigurationPropertiesRegistrar.methodValidationExcludeFilter
org.springframework.boot.sql.init.dependency.DatabaseInitializationDependencyConfigurer$DependsOnDatabaseInitializationPostProcessor
org.springframework.context.annotation.internalAutowiredAnnotationProcessor
org.springframework.context.annotation.internalCommonAnnotationProcessor
org.springframework.context.annotation.internalConfigurationAnnotationProcessor
org.springframework.context.event.internalEventListenerFactory
org.springframework.context.event.internalEventListenerProcessor
parameterNamesModule
preserveErrorControllerTargetClassPostProcessor
propertySourcesPlaceholderConfigurer
requestContextFilter
requestMappingHandlerAdapter
requestMappingHandlerMapping
resourceHandlerMapping
restTemplateBuilder
restTemplateBuilderConfigurer
routerFunctionMapping
scheduledBeanLazyInitializationExcludeFilter
server-org.springframework.boot.autoconfigure.web.ServerProperties
servletWebServerFactoryCustomizer
simpleControllerHandlerAdapter
spring.info-org.springframework.boot.autoconfigure.info.ProjectInfoProperties
spring.jackson-org.springframework.boot.autoconfigure.jackson.JacksonProperties
spring.lifecycle-org.springframework.boot.autoconfigure.context.LifecycleProperties
spring.mvc-org.springframework.boot.autoconfigure.web.servlet.WebMvcProperties
spring.servlet.multipart-org.springframework.boot.autoconfigure.web.servlet.MultipartProperties
spring.sql.init-org.springframework.boot.autoconfigure.sql.init.SqlInitializationProperties
spring.task.execution-org.springframework.boot.autoconfigure.task.TaskExecutionProperties
spring.task.scheduling-org.springframework.boot.autoconfigure.task.TaskSchedulingProperties
spring.web-org.springframework.boot.autoconfigure.web.WebProperties
standardJacksonObjectMapperBuilderCustomizer
stringHttpMessageConverter
taskExecutorBuilder
taskSchedulerBuilder
themeResolver
tomcatServletWebServerFactory
tomcatServletWebServerFactoryCustomizer
tomcatWebServerFactoryCustomizer
viewControllerHandlerMapping
viewNameTranslator
viewResolver
webServerFactoryCustomizerBeanPostProcessor
websocketServletWebServerCustomizer
welcomePageHandlerMapping
```다른 터미널 창을 열고 다음 명령어를 입력해 결과를 확인할 수 있습니다.
```shell
curl localhost:8080
Hello, World!
```### 실행 중지
다른 터미널 창에서 다음 명령어를 입력하면 실행 중지됩니다.
```shell
./gradlew -stop
```### 프로덕션급 서비스 추가
비즈니스를 위한 웹 사이트를 구축하는 경우 관리 서비스를 추가해야 할 수 있습니다. Spring Boot는 [actuator 모듈](https://docs.spring.io/spring-boot/docs/2.5.0/reference/htmlsingle/#actuator)과 함께 여러 서비스(상태, 감사, 빈 등)를 제공합니다.
Gradle을 사용하는 경우 `build.gradle` 파일에 다음 종속성을 추가합니다.
```groovy
implementation 'org.springframework.boot:spring-boot-starter-actuator'
```Maven을 사용하는 경우 `pom.xml` 파일에 다음 종속성을 추가합니다.
```xml
org.springframework.boot
spring-boot-starter-actuator```
다시 애플리케이션을 실행하면 새로운 RESTful 엔드포인트 세트가 추가된 것을 확인할 수 있습니다. Spring Boot에서 제공하는 관리 서비스입니다.
```shell
management.endpoint.configprops-org.springframework.boot.actuate.autoconfigure.context.properties.ConfigurationPropertiesReportEndpointProperties
management.endpoint.env-org.springframework.boot.actuate.autoconfigure.env.EnvironmentEndpointProperties
management.endpoint.health-org.springframework.boot.actuate.autoconfigure.health.HealthEndpointProperties
management.endpoint.logfile-org.springframework.boot.actuate.autoconfigure.logging.LogFileWebEndpointProperties
management.endpoints.jmx-org.springframework.boot.actuate.autoconfigure.endpoint.jmx.JmxEndpointProperties
management.endpoints.web-org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties
management.endpoints.web.cors-org.springframework.boot.actuate.autoconfigure.endpoint.web.CorsEndpointProperties
management.health.diskspace-org.springframework.boot.actuate.autoconfigure.system.DiskSpaceHealthIndicatorProperties
management.info-org.springframework.boot.actuate.autoconfigure.info.InfoContributorProperties
management.metrics-org.springframework.boot.actuate.autoconfigure.metrics.MetricsProperties
management.metrics.export.simple-org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleProperties
management.server-org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties
```acuator는 다음을 보여줍니다.
- actuator/health
- actuator다음 명령을 실행하여 애플리케이션의 상태를 확인할 수 있습니다.
```shell
curl localhost:8080/actuator/health
``````shell
{"status":"UP"}
```또한 `curl`을 통해 `shutdown`을 호출하여 `application.properties`에 필요한 줄을 추가하지 않았을 때 어떤 일이 발생하는지 확인할 수 있습니다.
```shell
curl -X POST localhost:8080/actuator/shutdown
``````shell
{"timestamp":"2022-05-09T05:20:46.427+00:00","status":404,"error":"Not Found","path":"/actuator/shutdown"}
```활성화하지 않았기 때문에 요청한 끝점을 사용할 수 없습니다(끝점이 존재하지 않기 때문에).
이러한 각 REST 끝점에 대한 자세한 내용과 `application.properties` 파일(`src/main/resources`에 있음)을 사용하여 해당 설정을 조정하는 방법은 [끝점에 대한 설명서](https://docs.spring.io/spring-boot/docs/2.5.0/reference/htmlsingle/#production-ready-endpoints)를 참조하세요.
### Groovy 지원
Spring Boot는 Groovy를 지원하므로 단일 파일로 Spring MVC 웹 애플리케이션을 구축할 수 있습니다.
`app.groovy`라는 새 파일을 만들고 여기에 다음 코드를 작성합니다. (위치는 어디든 상관 없습니다.)
```groovy
@RestController
class ThisWillActuallyRun {@GetMapping("/")
String home() {
return "Hello, World!"
}}
```다음으로 [Spring Boot's CLI](https://docs.spring.io/spring-boot/docs/2.5.0/reference/htmlsingle/#getting-started-installing-the-cli)를 설치합니다.
다음 명령을 실행하여 Groovy 애플리케이션을 실행합니다.
```shell
spring run app.groovy
```다른 터미널 창에서 다음 curl 명령을 실행합니다.
```shell
curl localhost:8080
``````shell
Hello, World!
```### 레퍼런스
-