diff --git a/springboot/external-read/src/main/java/hello/ExternalReadApplication.java b/springboot/external-read/src/main/java/hello/ExternalReadApplication.java index 89433b26..36135560 100644 --- a/springboot/external-read/src/main/java/hello/ExternalReadApplication.java +++ b/springboot/external-read/src/main/java/hello/ExternalReadApplication.java @@ -1,14 +1,16 @@ package hello; -import hello.config.MyDataSourceEnvConfig; -import hello.config.MyDataSourceValueConfig; +import hello.config.MyDataSourceConfigV1; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.context.properties.ConfigurationPropertiesScan; import org.springframework.context.annotation.Import; //@Import(MyDataSourceEnvConfig.class) -@Import(MyDataSourceValueConfig.class) +//@Import(MyDataSourceValueConfig.class) +@Import(MyDataSourceConfigV1.class) @SpringBootApplication(scanBasePackages = "hello.datasource") +@ConfigurationPropertiesScan public class ExternalReadApplication { public static void main(String[] args) { diff --git a/springboot/external-read/src/main/java/hello/config/MyDataSourceConfigV1.java b/springboot/external-read/src/main/java/hello/config/MyDataSourceConfigV1.java new file mode 100644 index 00000000..2b1c5993 --- /dev/null +++ b/springboot/external-read/src/main/java/hello/config/MyDataSourceConfigV1.java @@ -0,0 +1,28 @@ +package hello.config; + +import hello.datasource.MyDataSource; +import hello.datasource.MyDatasourcePropertiesV1; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; + +@Slf4j +@RequiredArgsConstructor +//@EnableConfigurationProperties(MyDatasourcePropertiesV1.class) +public class MyDataSourceConfigV1 { + + private final MyDatasourcePropertiesV1 properties; + + @Bean + public MyDataSource dataSource() { + return new MyDataSource( + properties.getUrl(), + properties.getUsername(), + properties.getPassword(), + properties.getEtc().getMaxConnection(), + properties.getEtc().getTimeout(), + properties.getEtc().getOptions() + ); + } +} diff --git a/springboot/external-read/src/main/java/hello/datasource/MyDatasourcePropertiesV1.java b/springboot/external-read/src/main/java/hello/datasource/MyDatasourcePropertiesV1.java new file mode 100644 index 00000000..d4a98498 --- /dev/null +++ b/springboot/external-read/src/main/java/hello/datasource/MyDatasourcePropertiesV1.java @@ -0,0 +1,26 @@ +package hello.datasource; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; + +import java.time.Duration; +import java.util.ArrayList; +import java.util.List; + +@Data +@ConfigurationProperties("my.datasource") +public class MyDatasourcePropertiesV1 { + + private String url; + private String username; + private String password; + private Etc etc; + + @Data + public static class Etc { + + private int maxConnection; + private Duration timeout; + private List options = new ArrayList<>(); + } +}