package com.spring.infra.db; import javax.sql.DataSource; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import com.zaxxer.hikari.HikariDataSource; /** * 보조 데이터 소스 설정을 위한 구성 클래스입니다. * *
이 클래스는 애플리케이션의 보조 데이터 소스를 설정하며, 다음과 같은 기능을 제공합니다:
*이 메소드는 'spring.datasource.secondary' 접두사로 시작하는 설정을 읽어 * DataSourceProperties 객체를 생성합니다.
* * @return 설정된 DataSourceProperties 객체 */ @Bean(name = DATASOURCE_PROPERTIES) @ConfigurationProperties(prefix = DATASOURCE_PROPERTIES_PREFIX) DataSourceProperties dataSourceProperties() { return new DataSourceProperties(); } /** * 보조 데이터 소스를 생성합니다. * *이 메소드는 설정된 DataSourceProperties를 사용하여 HikariCP 데이터 소스를 생성합니다.
* * @param properties 데이터 소스 속성 * @return 생성된 DataSource 객체 */ @Bean(name = DATASOURCE) DataSource dataSource(@Qualifier(DATASOURCE_PROPERTIES) DataSourceProperties properties) { return properties.initializeDataSourceBuilder().type(HikariDataSource.class).build(); } }