Anitha
Anitha

Reputation: 11

Spring boot issue in Autowiring

We are basically trying to acheive password change without restart of service as defined in https://blog.jdriven.com/2021/06/configure-hikari-connection-pool-when-using-rds-iam/ Implemented as shown below in the snippet I have to call the CustomDatasource with new keyword as we have to create new connection as its Multitenant enabled service

serviceA bean is null in getPassword() method in CustomDatasource

@Service public class CustomDatasource extends HikariDataSource {

 @Autowired
 private ServiceA serviceA;

 @Autowired
 public CustomDatasource(HikariConfig hikariConfig) {
     super(hikariConfig);
 }

 @Override
 public String getPassword() {
     serviceA.someMethod();
 }

}

@Service public class HikariDataSourceBuilder {

 CacheStore.getCache().setDataSource(new CustomDatasource(getHikariConfig(tenantId));

     public HikariConfig getHikariConfig(String tenant) {
         return hikariConfig;
     }
 }


 @Service
 public class ServiceA {

     public String someMethod() {
         return "";
     }
 }

Options tried Made CustomDatasource as @Scope(scopeName = ConfigurableBeanFactory.SCOPE_PROTOTYPE), so that everytime new instance of the class is returned, and made changes to get the bean from Application context in HikariDataSourceBuilder.java class Tried few other options by defining Postcontruct in CustomDatasource and also by changing the way ServiceA set in CustomDatasource

Upvotes: 0

Views: 31

Answers (0)

Related Questions