Reputation: 8106
I have been using Spring 3.2+ for some time now, Most of the time I am able to use either of the below options and it works, but I want to know if there is any specific difference.
Here is my JndiConfig java configuration class:
@Configuration
public class JndiConfig {
@Bean(name = "dataSource")
public DataSource dataSource() throws Exception {
BasicDataSource datasource = new BasicDataSource();
datasource.setDriverClassName("com.mysql.jdbc.Driver");
datasource.setUrl("jdbc:mysql://localhost:3306/csdb");
datasource.setUsername("root");
datasource.setPassword("root");
datasource.setValidationQuery("SELECT 1");
return datasource;
}
}
I can use the following options:
OPTION 1
@Configuration
@Import({JndiConfig.class})
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private DataSource dataSource;
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.jdbcAuthentication().dataSource(dataSource);
}
}
OPTION 2
@Configuration
@EnableWebSecurity
@ComponentScan(basePackages = "com.security"
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private DataSource dataSource;
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.jdbcAuthentication().dataSource(dataSource);
}
}
In the option 1 I import the JndiConfig
where as in option 2 I just do a component scan for JndiConfig
.
Can anyone explain me the difference between these two?
Thanks.
Upvotes: 1
Views: 898
Reputation: 2803
Right now I can only figure out two differences:
Upvotes: 1