How to dynamically configure DataSource in Spring based on application mode? <p>We have an application which runs both as standalone Spring application and as Webservice in Weblogic. The standalone application creates the database DataSource as show below by reading the properties file.</p> <p>However for the Webservices part, I'd like to use the DataSource configured in Weblogic via JNDI. I'm not sure how to make that dynamic DataSource switch based on the mode my application runs. Any help here please? </p> <pre><code>@Configuration @PropertySources(value = {@PropertySource("classpath:app.properties")}) public class DAOConfig { @Autowired Environment env; @Bean(destroyMethod = "close") public DataSource dataSource() { return new DataSources.Builder() .host(env.getProperty("dbhost")) .port(env.getProperty("dbport", Integer.class)) .service(env.getProperty("dbservice")) .user(env.getProperty("dbuser")) .pwd(env.getProperty("dbpwd")) .initialConnectionsInPool(env.getProperty("dbinitialConnectionsInPool", Integer.class)) .maxConnectionsInPool(env.getProperty("dbmaxConnectionsInPool", Integer.class)) .build(); } } </code></pre>