I am developing a web application based on Spring MVC framework. In this application I need to persist some data to DB.
I intend to use Spring data JPA as well. Now where is the best place to have the Datasource configured? I intend to deploy this in Apache tomcat.
I guess we have two places:
1) Define in the spring configuration file, like below:
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.h2.Driver"/>
<property name="url" value="jdbc:h2:tcp://localhost:9092/~/test"/>
<property name="username" value="sa"/>
<property name="password" value=""/>
</bean>
OR
2) Define in the Tomcat.
Is my understanding correct? Are there any difference in approaches in #1 and #2?
If we use #2, can Spring do dependency injection to the Datasource when needed by the application? OR can we reference the Datasource by JNDI lookup in this scenario?
I am learning this of my own, to understand how real life applications work; so any deeper insight would be of great help.