I am trying to understand in real life Enterprise applications (e.g. web-application, using Spring Framework) who should manage the Data source? I can think of two ways:
(i) Data source defined in Spring configuration and on need basis the application can get the data source from the Spring container.
(ii) Data source defined in web-container (for example) and then the application can get the data source from the container.
Now, I have following questions:
Q1) In scenario (i) I believe we can use Spring's DI to inject the Data source as it is managed by Spring. Is it correct?
Q2) In scenario (ii), the only way to get the Data source would be using the JNDI lookup, as the data source is configured in the container, and hence Spring won't be able to do DI. Is the correct?
Q3) When the Data source is managed by the Spring Container, would it be able to handle connection pooling
, global transaction
etc., if so, how? Does it internally use some third party libraries to achieve all this?
Any detailed information on this really appreciated.