Database connection management in Spring

后端 未结 5 1927
栀梦
栀梦 2021-01-21 09:25

Do we have to explicitly manage database resources when using Spring Framework.. liking closing all open connections etc?

I have read that Spring relieves developer from

5条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-21 10:15

    you say "The jdbcTemplate is configured in the xml file". You should normally create a new instance of the jdbcTemplate for each usage, not have it managed by spring.

    I would guess that each time you request a new jdbcTemplate bean from spring, it is creating a new one with a new connection to the database, but after it falls out of scope in your code it is still referenced by spring's applicationContext, and so does not close the connection.

提交回复
热议问题