tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stephan Beutel <beu...@axivion.com>
Subject Re: Context.xml for multiple datasources
Date Wed, 09 Feb 2011 10:12:22 GMT
  Am 09.02.2011 11:03, schrieb chris derham:
>> And the question is:
>> How to build the context to move the existing Spring configuration to the
>> Tomcat context to get all datasources with JNDI.
>> The problem is, that it must be possible to set a variable amount of
>> databases. I can't set the number of databases to a fixed amount.
>>
> Building the Resources for the beans named parentDataSource, firstDataSource
>> and secondDataSource is like configuring a single database.
>> But How can I create a JNDI lookable resource like the bean named
>> dataSource containing a map of all available database resources?
>>
> > From your original post, in which you stated "This is my working Spring
> datasource.xml:"
>
> <bean id="dataSource" class="com.ax.dashboard.
> datasource.AxRoutingDataSource">
> <property name="targetDataSources">
> <map key-type="java.lang.String">
> <entry key="first" value-ref="firstDatasource" />
> <entry key="second" value-ref="secondDataSource" />
> </map>
> </property>
> <property name="defaultTargetDataSource" ref="firstDatasource" />
> </bean>
>
> In spring you are building a map of data sources that are also defined in
> spring. Why not build a map of data sources that are defined in context.xml
> and spring looks them up? You say that you need variable amounts of
> databases, but the code you posted and said "this worked" doesn't support
> this - to add a new datasource you would have to update spring config. If
> you really need variable databases, then some custom code to load a custom
> configuration of such data sources might be the way to go. Then just use a
> resource element in context to get tomcat to load that for the instance.
>
> Chris
>
That's right, my code doesn't support a variable amount of databases at 
the moment because
the databases are configured in Spring (inside my war file).
But if I use the context to configure this list of datasources, the 
admin can create databases as he need.
And that's the reason why my configuration has to take place in the 
server context and not hardcoded in the Spring configuration.
In Spring I can add more databases as I want, but I have to rebuild my 
war file after change the datasource.
With a context configuration my war file can handle as many databases as 
the admin configures.
The switch is done by the key of the map.

Stephan

-- 
*Stephan Beutel (B.Eng.)*
Senior Software Developer

Axivion GmbH
Nobelstr. 15
70569 Stuttgart
Germany

Tel: +49 711 6204378-66
Fax: +49 711 6204378-99

Mail: beutel@axivion.com <mailto:beutel@axivion.com>
URL: http://www.axivion.com

Geschaeftsfuehrung: Stefan Bellon, Thomas Eisenbarth, Sebastian Rummler
Sitz der Gesellschaft: Stuttgart
Registergericht: Amtsgericht Stuttgart, HRB 720590


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message