英文:
Creating multiple DataSource in Spring framework is expensive
问题
在我的Spring MVC应用程序中,我有两个不同的MySQL数据库连接。
一个用于整个数据存储,另一个用于登录历史记录,每天在特定时间段插入数据。
我已经为jdbcTemplate创建了两个单独的数据源(一个通过spring.xml,另一个通过配置类)。这两个数据源都会在Tomcat启动时创建。
1)在一个应用程序中创建多个数据源(一个通过spring.xml,另一个通过@Configuration类)是否会很昂贵?
2)是否最好只在插入数据时连接和关闭第二个数据库(使用普通的JDBC连接)?
3)在一个应用程序中同时使用spring.xml和基于注解的配置是否是不良实践?
有人可以帮助我吗?
英文:
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.
- Does creating multiple Datasource (one via spring.xml and other one via @configuration class) in one application is expensive ?
- Will it be better to connect and close (normal jdbc connection) the second database only at the time insertion ?
- Is it bad practice to use both spring.xml and annotation based configuration in one application?
Can someone help me for this?
答案1
得分: 1
-
创建多个数据源(一个通过spring.xml,另一个通过@Configuration类)在一个应用程序中会很昂贵吗?
=> 不会,不过应该使用@Configuration类,我认为这样更容易管理。 -
是否在仅在插入时连接并关闭第二个数据库(普通jdbc连接)会更好?
=> 不会,不应该这样做。初始化连接的代价相当高,你可以为两个数据源都初始化连接池。 -
在一个应用程序中同时使用spring.xml和基于注解的配置是否是不良实践?
=> 同问题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 -
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 -
Is it bad practice to use both spring.xml and annotation based configuration in one application?
=> Same 1, both are OK
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论