Spring/Spring Boot 15

[Spring Boot] 5. Executable Jars

Spring Boot는 spring-boot-loader 모듈을 가지고 executable jar와 war를 로드합니다. spring-boot-loader 모듈은 build tool의 plugin을 통해 자동으로 셋팅됩니다. Gradle Plugin plugins { id 'java' id 'org.springframework.boot' version '3.0.4' } java 플러그인이 적용되어 있을 경우, spring boot 플러그인은 spring-boot-loader 모듈을 자동으로 추가합니다. spring-boot-loader 모듈은 executable jar 을 로드하고 실행할 수 있도록 도와주는 역할을 맡습니다. 1. Nested JARs Java는 기본적으로 중첩 jar를 로드하고 압축하는..

Spring/Spring Boot 2023.10.13

[Spring Boot] 4. Data: SQL Databases

1. SQL Database Spring Framework는 광범위한 SQL Database 와의 작업을 지원합니다. JdbcTemplate : JDBC 기술을 사용하여 기존의 코드를 단순화화고, 오류 처리 및 리소스 관리를 개선한 헬퍼 클래스 Hibernate : JPA 기반 ORM 기술 Spring Data JPA는 Repository 인터페이스를 제공합니다. Repository 인터페이스 구현을 통해 Entity 관련 Table과 직접적으로 통신할 수 있습니다. Repository 인터페이스가 제공하는 메서드 이름의 컨벤션으로 메서드를 생성하면 자동으로 관련 쿼리를 생성하여 통신합니다. Configure a DataSource java의 javax.sql.DataSource 인터페이스는 databa..

Spring/Spring Boot 2023.10.13

[Spring Boot] 3. Web: Servlet Web Application

1. The “Spring Web MVC Framework” Spring Web MVC는 풍부한 기능을 가진 "model-view-controller" 웹 프레임워크 입니다. Controller @Controller (or @RestController) 빈으로 들어오는 요청을 처리하도록 돕습니다 @Controller 빈의 메서드는 @RequestMapping을 사용하여 요청을 URI 기반으로 매핑할 수 있습니다. ConversionService 객체의 타입을 다른 타입으로 변환하는 인터페이스입니다. Spring Boot에서는 ApplicationConversionService를 기본 구현체로 사용합니다. @ConfigurationProperties 바인딩, SpringWeb MVC 포맷에서 주로 사용됩니..

Spring/Spring Boot 2023.10.12

[Spring Boot] 2-10. Core Features: Auto-Configuration

Spring Boot에서 제공하는 Starter 모듈을 의존성으로 사용하면, 번들링된 Auto-Configuration 라이브러리가 함께 제공됩니다. Spring Boot는 번들링된 Auto-Configuration 라이브러리를 픽업하여 적용합니다. 1. Understanding Auto-configured Beans @AutoCofigure* 어노테이션은 관련 자동설정을 활성화하는 기능을 담당합니다. 자동설정 클래스는 *AutoConfiguration 패턴으로 @AutoConfiguration가 붙어 있습니다. 자동설정 클래스의 메서드를 실행하여 자동 설정을 활성화합니다. 각 메서드는 자신의 자동 설정과 관련된 컴포넌트를 빈으로 등록합니다. @Conditional, @ConditionalOnClass,..

Spring/Spring Boot 2023.10.11

[Spring Boot] 2-8. Core Features: Test

Spring Boot는 spring-boot-starter-test 모듈을 통해 test를 위한 어노테이션과 유틸클래스, 테스트 라이브러리를 제공합니다. 1. Test Scope Dependencies spring-boot-test : test core feature spring-boot-test-autoconfigure : test auto-configuration assertj-core : 표현식을 가진 단언 라이브러리 hamcrest : 매처 라이브러리 junit-jupiter : junit5 핵심 모듈. (unit test 프레임워크) mockito-core, mockito-junit-jupiter : mocking, stubbing 프레임워크 JsonPath : JSON을 위한 XPath 모듈 ..

Spring/Spring Boot 2023.10.11

[Spring Boot] 2-6. Core Features: JSON

1. Jackson jackson은 Spring Boot에서 기본적으로 제공되는 JSON 직렬화 도구입니다. spring-boot-starter-json 모듈의 도구입니다. auto-configuration 기능으로 제공되는 도구입니다. 직렬화를 담당하는 클래스인 ObjectMapper가 자동으로 설정됩니다. Custom Serializers and Deserializers ObjectMapper는 JsonSerializer와 JsonDeserializer 클래스를 사용하여 직렬화 및 역직렬화를 담당합니다. @JsonComponent public class MyJsonComponent { public static class Serializer extends JsonSerializer { @Override..

Spring/Spring Boot 2023.10.09

[Spring Boot] 2-3. Core Features: Profile

profile은 애플리케이션의 설정을 분리하여 특정 프로파일에 필요한 환경설정을 제공할 수 있습니다. @Profile 어노테이션을 통해 해당 클래스가 어떤 profile에 적용될지 가리킬 수 있습니다. 어떤 프로파일을 활성화할지 명시할 수 있습니다. property : spring.profiles.active command line args : --spring.profiles.active 기본 프로파일을 명시할 수 있습니다. property : spring.profiles.default 프로파일 활성화 조건을 명시할 수 있습니다. property : spring.config.activate.on-profile 1. Adding Active Profiles spring.profiles.active 프로퍼티..

Spring/Spring Boot 2023.10.09

[Spring Boot] 2-2. Core Features: Externalized Configuration

Spring Boot는 외부 설정을 통해 같은 코드를 다양한 환경에서 실행할 수 있게 지원합니다. 이 설정은 프로퍼티 파일, YAML 파일, 환경 변수, 명령행 인자 등을 통해 제공될 수 있습니다. 이러한 설정 값들은 @Value 어노테이션 또는 @ConfigurationProperties를 사용하여 애플리케이션의 빈에 주입될 수 있습니다. Spring Environment는 여러 PropertySource를 관리하며, 각 PropertySource는 정해진 우선순위에 따라 동작합니다. 동일한 프로퍼티 키가 여러 PropertySource에 존재할 경우, 늦게 등장하는 순서의 PropertySource 값으로 오버라이드됩니다. 0. PropertySource 순서 Default properties (Sp..

Spring/Spring Boot 2023.10.09

[Spring Boot] 2-1. Core Features: SpringApplication 클래스

1. SpringApplication SpringApplication 클래스는 Spring application을 편리하게 기동하는 방법을 제공하는 클래스입니다. SpringApplication.run 메서드가 main method로부터 호출되어 bootstrapping 작업을 시작합니다. 기본적으로 INFO 레벨의 로그가 찍이도록 설정됩니다. startup과 연관된 메시지가 출력됩니다. Startup Failure FaliureAnalyzers는 Spring Boot 기동중 에러 발생 시 문제 해결을 담당합니다. 여러 구현체를 가지고 있습니다. 에러 메시지를 출력합니다. 에러를 처리할 수 없다면, 원인 파악을 위해 DEBUG 레벨의 로그를 확인해야 합니다. DEBUG 레벨 로그는 Full Conditi..

Spring/Spring Boot 2023.10.08