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 551d0b7 commit 8a14ac1
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 14 deletions.
22 changes: 17 additions & 5 deletions .idea/workspace.xml

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

21 changes: 19 additions & 2 deletions src/main/java/guru/springframework/sfgdi/SfgDiApplication.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package guru.springframework.sfgdi;

import guru.springframework.sfgdi.config.SfgConfiguration;
import guru.springframework.sfgdi.controllers.*;
import guru.springframework.sfgdi.datasource.FakeDataSource;
import guru.springframework.sfgdi.services.PrototypeBean;
Expand Down Expand Up @@ -50,12 +51,28 @@ public static void main(String[] args) {
PrototypeBean prototypeBean2 = ctx.getBean(PrototypeBean.class);
System.out.println(prototypeBean2.getMyScope());

System.out.println("--------- Fake Data Source");
FakeDataSource fakeDataSource = ctx.getBean(FakeDataSource.class);
System.out.println(fakeDataSource.getUsername());
System.out.println(fakeDataSource.getPassword());
System.out.println(fakeDataSource.getJdbcurl());



System.out.println("--------- Config Props Bean");
SfgConfiguration sfgConfiguration = ctx.getBean(SfgConfiguration.class);
System.out.println(sfgConfiguration.getUsername());
System.out.println(sfgConfiguration.getPassword());
System.out.println(sfgConfiguration.getJdbcurl());
}

}











Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,18 @@
import guru.springframework.sfgdi.repositories.EnglishGreetingRepository;
import guru.springframework.sfgdi.repositories.EnglishGreetingRepositoryImpl;
import guru.springframework.sfgdi.services.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.*;

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

@Bean
FakeDataSource fakeDataSource(@Value("${guru.username}") String username,
@Value("${guru.password}") String password,
@Value("${guru.jdbcurl}") String jdbcurl) {
FakeDataSource fakeDataSource(SfgConfiguration sfgConfiguration) {
FakeDataSource fakeDataSource = new FakeDataSource();
fakeDataSource.setUsername(username);
fakeDataSource.setPassword(password);
fakeDataSource.setJdbcurl(jdbcurl);
fakeDataSource.setUsername(sfgConfiguration.getUsername());
fakeDataSource.setPassword(sfgConfiguration.getPassword());
fakeDataSource.setJdbcurl(sfgConfiguration.getJdbcurl());
return fakeDataSource;
}

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

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

@ConfigurationProperties("guru")
@Configuration
public class SfgConfiguration {
private String username;
private String password;
private String jdbcurl;

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public String getJdbcurl() {
return jdbcurl;
}

public void setJdbcurl(String jdbcurl) {
this.jdbcurl = jdbcurl;
}
}

0 comments on commit 8a14ac1

Please sign in to comment.