上QQ阅读APP看书,第一时间看更新
Step 5—Spring application configuration
Create a Java class named ApplicationConfig with the following code in the com.packtpub.book.ch02.springsecurity.config package:
@Configuration
@PropertySource("classpath:mysqldb.properties")
public class ApplicationConfig {
@Autowired
private Environment env;
@Bean
public DataSource getDataSource() {
BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName(env.getProperty("mysql.driver"));
dataSource.setUrl(env.getProperty("mysql.jdbcUrl"));
dataSource.setUsername(env.getProperty("mysql.username"));
dataSource.setPassword(env.getProperty("mysql.password"));
return dataSource;
}
}