Using dynamic Datasource with Tomcat

后端 未结 1 1071
心在旅途
心在旅途 2020-12-19 16:02

I\'m creating a series of webservices for my application and i have the need to access a different database based on the serviceCode that is passed as a parameter in the web

相关标签:
1条回答
  • 2020-12-19 16:27

    Define your own Resource. See the Tomcat documentation. You provide an implementation of javax.naming.spi.ObjectFactory. Have it return an appropriate implementation of Context such that looking it up via some name returns a DB connection to that name. In my case the required entry in context.xml looked like this:

    <Resource
        name="ldap/Context" // your name, probably something like jdbc/dynamic
        auth="Container"
        type="javax.naming.ldap.LdapContext"
        factory="com.xxxx.ldap.LdapContextFactory"
        // your initialization params here, if any
        >
    
    0 讨论(0)
提交回复
热议问题