Multiple JdbcTemplate instances or not?

后端 未结 4 1728
一向
一向 2021-02-04 01:01

From what I understand, both DataSource and JdbcTemplates are threadsafe, so you can configure a single instance of a JdbcTempla

4条回答
  •  名媛妹妹
    2021-02-04 01:52

    After so many years, and see this question again, I think we can create "Jdbc Template" with singleton first, then inject to DAO, so it is only one instance For the Template.

    
        
    
    

    then you can inject template to DAO or DAO extends JdbcDaoSupport.

    public final void setJdbcTemplate(JdbcTemplate jdbcTemplate)
    {
       this.jdbcTemplate = jdbcTemplate;
       initTemplateConfig();
    }
    

提交回复
热议问题