spring - Singleton vs prototype JdbcTemplate -
in spring documentation recommended way use jdbctemplate create new
template every class use in...
public class jdbccorporateeventdao implements corporateeventdao { private jdbctemplate jdbctemplate; public void setdatasource(datasource datasource) { this.jdbctemplate = new jdbctemplate(datasource); } }
i wondering, advantage of solution on define jdbctemplate
singleton in context , directly inject in dao
public class jdbccorporateeventdao implements corporateeventdao { @autowired private jdbctemplate jdbctemplate; public void setjdbctemplate(jdbctemplate jdbctemplate) { this.jdbctemplate = jdbctemplate; } }
from class-level documentation of jdbctemplate:
* can used within service implementation via direct instantiation * datasource reference, or prepared in application context * , given services bean reference.
either ok. here have large application (50 daos, 100 concurrent users) , there 1 jdbctemplate object entire application, defined in spring context. works fine.
Comments
Post a Comment