Spring datasource configuration for localhost, development, and production

前端 未结 6 910
暖寄归人
暖寄归人 2021-02-02 00:53

I\'m trying to figure out how my Spring app can determine where it is deployed and load the appropriate datasource. We have 3 environments...my local, the development server, a

6条回答
  •  北海茫月
    2021-02-02 01:10

    For data sources the easiest way would be to define data sources and let the container manage the connection pooling.

    To do so, define a resource reference to the data source in web.xml

    
      DB Connection
      jdbc/MyDataSource
      javax.sql.DataSource
      Container
    
    

    and reference it in spring as such:

    
    

    then you can define the data source in the application server, which means you can change the underlying database. In case of websphere, this would be done through the websphere console. In case of tomcat, it would be done through the Context.xml:

    
        ...
      
    
    

    That way you only need to change the context to deploy to development, test and production and don't tie your application to a specific database.

提交回复
热议问题