performance - Difference between declaring data source via tomcat context file and spring context -
is there difference between declaring datasource
in meta-if/context.xml
file , spring bean using jndi lookup (approach 1), or declaring datasource
directly via spring (approach 2) :
@bean(destroymethod = "close") datasource datasource(environment env) { hikariconfig datasourceconfig = new hikariconfig(); datasourceconfig.setdriverclassname(env.getrequiredproperty(property_name_db_driver_class)); datasourceconfig.setjdbcurl(env.getrequiredproperty(property_name_db_url)); datasourceconfig.setusername(env.getrequiredproperty(property_name_db_user)); datasourceconfig.setpassword(env.getrequiredproperty(property_name_db_password)); return new hikaridatasource(datasourceconfig); }
i think second approach better because not tied specefic server, means if use first approach , 1 day migrate server must adapt strategie of context file in second server (not true ?).
thanks
some points first approach (jndi lookup of datasource defined in container):
- can configured without touching actual application
- it possible secure sensitive information (like password) better
- datasource may shared between many applications on same server
i use first approach security (or "security") reasons when required - often, customer's requirement password db access must not stored in application in plain text. possible response not store password in application @ all , instead leave customer provide datasource through jndi.
this makes sense system administration point of view - if data source ever needs reconfigured, due infrastructure or network change, should in administrator's power (and responsibility) reconfigure data source well. servlet container should such place.
if don't need of above, use second approach (less complicated, easier deploy).
Comments
Post a Comment