开发者

servlet - many contexts - how to share db connection?

I have .war file A and .war file B and .war file C; B and C need to use database connection so I decided to use .war A to share database connection. But the problem is that .war files are limited with their own contexts. So my question is how to get database开发者_运维技巧 connection to share it among my Tomcat web apps? And how to limit the connection access just for a few apps?


You probably don't actually want to share a single connection across apps. You probably want to share the thing that creates connections, which should be a connection pool. Put an appropriate implementation of DataSource into Tomcat's JNDI registry. Then all apps can retrieve a connection from the same source. To restrict access to some apps, just force them to use the getConnection() method that requires a username and password, and only the apps that have credentials can use it.


Declare in your Tomcat's server.xml a dataSource resource and reference that in your context.xml. This covers your case.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜