-1

In my spring mvc application , I have two different MySql database connections. One is for whole data storage and other one is for login history- which insert data daily in a specific period.

I have created two separate Datasource (one via spring.xml and other via configuration class) for jdbcTemplate. Both will created at the time of tomcat start.

  1. Does creating multiple Datasource (one via spring.xml and other one via @configuration class) in one application is expensive ?
  2. Will it be better to connect and close (normal jdbc connection) the second database only at the time insertion ?
  3. Is it bad practice to use both spring.xml and annotation based configuration in one application?

Can someone help me for this?

Arun
  • 107
  • 2
  • 2
  • 10

1 Answers1

1
  1. Does creating multiple Datasource (one via spring.xml and other one via @configuration class) in one application is expensive ? => No, It doesn't. but should use Configuration classes, It's easier to manage IMO

  2. Will it be better to connect and close (normal jdbc connection) the second database only at the time insertion ? => No, It won't. To init a connection quite costly, you can init connection pools for both DS

  3. Is it bad practice to use both spring.xml and annotation based configuration in one application? => Same 1, both are OK

Rony Nguyen
  • 1,067
  • 8
  • 18
  • Got It, but the second database used for an experimental level and which will collect data to analyze user activity. But we don't want to break entire application if the less priority database crash- (due to datasource creation fail) – Arun Oct 09 '20 at 09:42
  • Is there anyway to disable/enable datasource creation by setting 'active status field' in database/property file externally? – Arun Oct 09 '20 at 09:43
  • - The first point, It seems that 2nd DB for analyzing data, so It can be a replica DB with read-only, It's will no impact to Primary DB. I do not get why you need to disable/enable on runtime by a setting. If DS is disabled mean that application can use that DS. If so you just disable/enable the application which is using that DS – Rony Nguyen Oct 09 '20 at 14:17
  • It was decided by the customer. Disable/Enabling configurations can be implemented by Condtional or Profile annotations. Is there anything else beneficial than these annotations? – Arun Oct 11 '20 at 07:48