SpringApplication.main
이 있었다.import 내프로젝트.메인Application
import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext
import org.springframework.context.ConfigurableApplicationContext
import javax.swing.Spring
import java.util.concurrent.ConcurrentHashMap
def MyService = 메인Application.class
// 끔찍하지만, 스프링 콘솔 특성상 어쩔수 없다!
// 같은 스크립트를 무한 실행해도 값을 덮어쓰지 않도록 조치하자.
try {GlobalSpringApplication = GlobalSpringApplication}
catch (Exception ignored){GlobalSpringApplication = null}
if (GlobalSpringApplication == null) GlobalSpringApplication = new SpringApplication(MyService)
// 스프링을 스레드에서 돌리기 위한 Runnable
// 이거로 스레드를 시작하면, 시작 함수 실행시 블로킹 되지 않는다.
// 매니지먼트는 알바 없다. 스캐폴딩에 그런게 무슨 소용인가?
class REPLSpringServerRunnable implements Runnable {
ConfigurableApplicationContext SpringContext
SpringApplication GlobalSpringApplication
REPLSpringServerRunnable(def GlobalSpringApplication) {
this.GlobalSpringApplication = GlobalSpringApplication as SpringApplication
}
void run() {
this.SpringContext = GlobalSpringApplication.run()
}
}
// 스프링 스레드 작업 시작
try {CurrentSpringApplication = CurrentSpringApplication}
catch (Exception ignored){CurrentSpringApplication = null}
if (CurrentSpringApplication == null) {
CurrentSpringApplication = new REPLSpringServerRunnable(GlobalSpringApplication)
new Thread(CurrentSpringApplication).start();
}
// 모든 빈을 불러온다!
def SpringApplicationContext = CurrentSpringApplication.springContext as AnnotationConfigServletWebServerApplicationContext
println ("=========================")
println ("Here is all the beans we have")
println ("------------------------")
for (final a in SpringApplicationContext.getBeanFactory().beanDefinitionMap) {
println (a.Key)
}
println ("=========================")
주르륵 다나온다.
...
commentResource
org.springframework.boot.autoconfigure.domain.EntityScanPackages
org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration$DefaultTemplateResolverConfiguration
org.springframework.boot.autoconfigure.security.servlet.SecurityFilterAutoConfiguration
springSecurityFilterChain
enableGlobalAuthenticationAutowiredConfigurer
servletWebServerFactoryCustomizer
mvcUrlPathHelper
...
지금 뜯어보는게 전에 예시 코드용으로 만든 게시판 프로젝트인데, 이 프로젝트에 있는 모든 댓글들을 따보자.
다 나온다.
이러면 일일히 curl날려서 검증할 필요가 없다. 왜냐면 날린거랑 이거랑 다른게 없기 때문이다.
스프링에서 가장 귀찮은 API및 메서드 검증을 미리 이렇게 하고 추후에 테스트로 박아넣으면 스프링도 꽤나 나쁘지 않다.
여기서 확인할 수 있는건, 컨트롤러, 서비스, 설정 등 모든 스프링 컴포넌트들이 Bean 취급 된다는 것.
사실 뭔가 다 분리되어있고 복잡한 모듈로 되어있는것처럼 보이지만, 사실 Bean이라는 핵심 아래에 여러 큰 베이스가 되는 클래스가 트리처럼 퍼지는 구조로 되어있다.
대부분이 자동화되어서 처리되는 구조라 퍽하고 터지거나 하지도 않은 일이 터지는 일이 잦게 되어있음
(특히 망할 Reflection을 통한 Method Proxy가 떡칠되어있는거 보고 이걸 디버깅 할 생각을 하지 않는게 좋다고 생각되었다.)