I think it will be hard (if not impossible) if you use app-local datasource. You can however share it if you install your datasource on the container (see Chapter 17. Datasource Configuration -- JBoss 5 reference). Container datasource will have a JNDI name which you can inject to Spring container using <jee:jndi-lookup>
tag:
<jee:jndi-lookup id="dataSource" jndi-name="jdbc/MyDataSource"/>
JNDI Datasource can be deployed not only administratively (admin console), but programmatic as well. Each war could have following code logic on Spring container initialization:
- Check if there exist a datasource with JNDI name "jdbc/MyDatasource".
- If doesn't exist, create one and deploy.
- If exist, just grab the reference, place it into Spring container.
However the weakness of this method is if you do have to change the datasource property (server ip / database name) later in the future you have to update and recompile every single war.
Configuring datasource on the container using admin console is a more popular approach in this regard.