1

I have 2 configuration class one with datasources configuration and the other is my WebSecurityConfig that extends WebSecurityConfigurerAdapter. I want to load DB values to be used in WebSecurityConfig, so I need to finish initing the datasources before WebSecurityConfig.

OracleConfiguration

@Configuration
@ConfigurationProperties("oracle")
@Order(Ordered.HIGHEST_PRECEDENCE)
public class OracleConfiguration {
   //data source beans...
}

WebSecurityConfig

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(securedEnabled = true)
@Order(Ordered.LOWEST_PRECEDENCE)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
//security configs like SAML...
}

And Still when I debugging, the code in WebSecurityConfig runs before the data sources init, datasource init example(inside OracleConfiguration)

@Bean
@Primary
DataSource dataSource() throws SQLException {
     //Init
    OracleDataSource dataSource = new OracleDataSource();
    dataSource.setUser(username);
    dataSource.setPassword(password);
    dataSource.setURL(url);
    dataSource.setImplicitCachingEnabled(true);
    dataSource.setFastConnectionFailoverEnabled(true);
    return dataSource;
}
Itsik Mauyhas
  • 3,824
  • 14
  • 69
  • 114

1 Answers1

0

Try put dataSource to some bean parameter in WebSecurityConfig. In this case beans in webSecurityConfig will depend from dataSource bean in OracleConfiguration. I think it will work.