[공부] 영상/스프링 부트 강의(16)
-
스프링 부트 강의 정리 (21~22 : 테스트 자동 설정 Annotations)
spring-boot-test-autoconfigure Configuration 을 슬라이싱해서 원하는 설정파일만 불러와서 테스트를 진행할 수 있도록 도와준다. 대부분의 @~Test 은 excludeAutoConfiguration 을 지원하므로 이를 사용하면 된다. (ex @JsonTest) 슬라이싱에 관심이 없으면 그냥 @SpringBootTest를 쓰면 된다. 말했다시피 @SpringBootTest는 메인 어플리케이션에 등록된 모든 설정파일을 읽어들인다. 그러므로 가능하면 @EnableBatchProcessing 과 같은 특정 목적을 위한 설정은 메인 어플리케이션에 달아두지 말자. 따로 Configuration 클래스를 둬서 관리하는 것이 좋다. 그렇지 않으면 이 설정을 받아들이는 테스트들이 Spri..
2019.04.28 -
스프링 부트 강의 정리 (19~20 : 테스트, MockBean)
스프링 부트 테스트 spring-boot-starter-test 를 사용하고 이 안에 spring-boot-test, spring-boot-test-autoconfigure 가 있다. JUnit, AssertJ, Harmcrest 라이브러리들을 가져온다. AssertJ : matcher 도 안쓰고 assertThat 만으로 Chaining 해서 테스트 코드 검증할 수 있어서 괜찮은 듯 https://joel-costigliola.github.io/assertj/ AssertJ / Fluent assertions for java AssertJ Fluent assertions for java joel-costigliola.github.io Dependency Injection의 가장 큰 장점은 테스트 코드 ..
2019.04.28 -
스프링 부트 강의 정리 (16~18 : 템플릿 엔진, 에러 핸들링, 데이터 바인딩)
스프링 부트 MVC는 다음과 같은 템플릿 엔진을 기본적으로 지원한다. FreeMarker (업데이트가 느려서 권장 x) Groovy Thymleaf Mustache JSP (사용을 권하지 않음) 위의 템플릿 엔진을 사용할 때 파일을 불러오는 기본 경로는 src/main/resources/templates 이다. Thymeleef 사용 예시 Thymeleef dependency 추가 org.springframework.boot spring-boot-starter-thymeleaf src/main/resources/templates/helloView.html src/main/com/testcompany/testproject/controller/HelloController.java @Controller pub..
2019.04.27 -
스프링 부트 강의 정리 (15 : WebJar)
WebJar : 프론트엔드 라이브러리를 jar 형태로 패키징해놓은 형태. JQuery 같은 것을 메이븐을 통해서 다운 받을 수 있다. 메이븐으로 설치한 JQuery를 프론트엔드에서 라이브러리를 사용할 수 있다. 추가한 라이브러리는 webjars/ 이하 경로를 통해서 가져올수있다. org.webjars jquery 3.4.0 HTML JQuery 선언 스프링 부트에서 캐시에 자유롭게 변경된 내용을 계속 반영해주는 방법 방법 1. 버전 agnostirng URL : org.webjars webjars-locator-core 방법 2. 캐시 버스팅 : 캐시될 파일 이름의 뒤에다 해쉬코드값을 붙여서 캐시에 독립적으로 동작하도록 한다. # Cache busting properties spring.resources..
2019.04.24 -
스프링 부트 강의 정리 (13~14 : HttpMessageConverter, Static content)
스프링 부트는 Tomcat, jetty, undertow, netty등을 내장하고 있어서 Web 개발에 유용하다. spring-boot-web 를 이용하면 빠르게 웹개발을 빠르게 시작해볼 수 있다. spring-boot-starter-webflux 를 이용하면 reactive web 어플리케이션을 개발 할 수 도 있다. spring mvc : controller, restcontroller 로 http request를 핸들링한다. spring boot 는 spring web mvc를 위한 auto configuration을 제공한다. Spring Web Auto-configuration의 특징 controller의 return string -> ViewResolver -> View -> ContentNe..
2019.04.21 -
스프링 부트 강의 정리 (11~12 : Profile, Log)
profile으로 local 환경 dev 환경 분리하기 https://kok202.tistory.com/114?category=782902 스프링 부트 개발환경 로컬환경 분리 application.yml 에 profile을 dev와 local 로 분할 spring: profiles: development ... --- spring: profiles: local ... 로컬환경으로 돌리고 싶을 경우 Run - Edit configurations -> Configuration ->VM optio.. kok202.tistory.com @Profile을 이용하면 profile 값에 따라서 주입받을 클래스를 바꿀 수 있다. public interface Parent { public String getMessage..
2019.04.21