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

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -