Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
blackswan-03 committed Jan 8, 2025
1 parent 8a14ac1 commit 84af73b
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 9 deletions.
19 changes: 14 additions & 5 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package guru.springframework.sfgdi;

import guru.springframework.sfgdi.config.SfgConfiguration;
import guru.springframework.sfgdi.config.SfgConstructorConfig;
import guru.springframework.sfgdi.controllers.*;
import guru.springframework.sfgdi.datasource.FakeDataSource;
import guru.springframework.sfgdi.services.PrototypeBean;
Expand Down Expand Up @@ -62,6 +63,12 @@ public static void main(String[] args) {
System.out.println(sfgConfiguration.getUsername());
System.out.println(sfgConfiguration.getPassword());
System.out.println(sfgConfiguration.getJdbcurl());

System.out.println("---------- Constructor Binding");
SfgConstructorConfig sfgConstructorConfig = ctx.getBean(SfgConstructorConfig.class);
System.out.println(sfgConstructorConfig.getUsername());
System.out.println(sfgConstructorConfig.getPassword());
System.out.println(sfgConstructorConfig.getJdbcurl());
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@
import guru.springframework.sfgdi.repositories.EnglishGreetingRepository;
import guru.springframework.sfgdi.repositories.EnglishGreetingRepositoryImpl;
import guru.springframework.sfgdi.services.*;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.*;

@EnableConfigurationProperties(SfgConstructorConfig.class)
@ImportResource("classpath:sfgdi-config.xml")
@Configuration
public class GreetingServiceConfig {

@Bean
FakeDataSource fakeDataSource(SfgConfiguration sfgConfiguration) {
FakeDataSource fakeDataSource(SfgConstructorConfig sfgConstructorConfig) {
FakeDataSource fakeDataSource = new FakeDataSource();
fakeDataSource.setUsername(sfgConfiguration.getUsername());
fakeDataSource.setPassword(sfgConfiguration.getPassword());
fakeDataSource.setJdbcurl(sfgConfiguration.getJdbcurl());
fakeDataSource.setUsername(sfgConstructorConfig.getUsername());
fakeDataSource.setPassword(sfgConstructorConfig.getPassword());
fakeDataSource.setJdbcurl(sfgConstructorConfig.getJdbcurl());
return fakeDataSource;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package guru.springframework.sfgdi.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.ConstructorBinding;

@ConstructorBinding
@ConfigurationProperties("guru")
public class SfgConstructorConfig {
private final String username;
private final String password;
private final String jdbcurl;

public SfgConstructorConfig(String username, String password, String jdbcurl) {
this.username = username;
this.password = password;
this.jdbcurl = jdbcurl;
}

public String getUsername() {
return username;
}

public String getPassword() {
return password;
}

public String getJdbcurl() {
return jdbcurl;
}
}

0 comments on commit 84af73b

Please sign in to comment.