Persisting and accessing data forms one of the most routine yet core functionalities of any application. In the world of JEE, there are many APIs as well as frameworks to achieve to achieve the same. The Spring Framework is no exception. This article will explain how to use this framework for persisting and accessing data in your applications.
Configuring the bean means providing a declaration for injecting the DataSource to the POJO or bean. It is done using the <ref> child tag of the <property> tag. The <ref> tag tells the Spring Framework that the current bean or POJO is referencing another bean. And the <property> tag tells the instance variable that it will receive the reference.
For example, the following statements tell the Spring Framework that the bean with the ID "dao" refers the bean with the of ID"dataSource." The implementation of DataSource will be received by the DataSource instance variable within the JdbcEventDao class. The following is the code for the same:
<bean id="dao" class=" JdbcEventDao ">
Finally, we are up to the third step, developing the client. To develop the client, you must do two things. First, you must retrieve an instance of the JdbcTemplate class. To do so, an implementation of DataSource needs to be retrieved using JdbcEventDao POJO. The following statements will retrieve the DataSource implementation as well as a JdbcTemplate instance:
Resource res = new ClassPathResource("beans.xml");