Databases Reference
In-Depth Information
@EnableJpaRepositories("com.packtpub.springdata.jpa.repository")
@EnableTransactionManagement
@EnableWebMvc
@PropertySource("classpath:application.properties")
public class ApplicationContext extends WebMvcConfigurerAdapter {
@Resource
private Environment env;
//Add configuration here
}
We can also configure Spring Data JPA by using XML. We can do
this by adding the repositories namespace element of Spring
Data JPA to our application context configuration file.
Configuring the data source bean
We will start the configuration of the data source bean by adding a dataSource()
method to the ApplicationContext class and annotating this method with the
@Bean annotation. The implementation of this method is as follows:
1.
Create an instance of the BoneCPDataSource class.
2.
Set the database connection details.
3.
Return the created object.
The configuration of the data source bean is given as follows:
@Bean
public DataSource dataSource() {
BoneCPDataSource ds = new BoneCPDataSource();
ds.setDriverClass(env.getRequiredProperty("db.driver"));
ds.setJdbcUrl(env.getRequiredProperty("db.url"));
ds.setUsername(env.getRequiredProperty("db.username"));
ds.setPassword(env.getRequiredProperty("db.password"));
return ds;
}
 
Search WWH ::




Custom Search