Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <context:component-scan base-package="org.dhana.*" />
- <context:annotation-config />
- <bean id="transactionManager"
- class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
- <property name="dataSource" ref="dataSource" />
- </bean>
- <bean id="dataSource"
- class="org.springframework.jdbc.datasource.DriverManagerDataSource">
- <property name="driverClassName" value="com.mysql.jdbc.Driver" />
- <property name="url"
- value="xxxx" />
- <property name="username" value="${db_username}" />
- <property name="password" value="xxxxx" />
- </bean>
- <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
- <property name="dataSource" ref="dataSource" />
- </bean>
- <bean id="propertyPlaceholderConfigurer"
- class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
- <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
- <property name="searchSystemEnvironment" value="true" />
- </bean>
- value="#{systemProperties['db_username']}"
- <context:property-placeholder location="file:${env_config_path}/configuration.properties" />
- -Denv_resource_path="/Users/mylogin/work/myproject/development_environment_resources"
- jdbc.userName = xxx
- jdbc.password = yyy
- <bean id = "prop"
- class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
- <property name="locations">
- <value>classpath*:xxxx.properties</value>
- </property>
- <bean id="dataSource"
- class="org.springframework.jdbc.datasource.DriverManagerDataSource">
- <property name="driverClassName" value="${}"/>
- <property name="url" value="${}"/>
- <property name="username" value="${jdbc.userName}"/>
- <property name="password" value="${jdbc.password}"/> </bean>
- jdbc.driverClassName=com.mysql.jdbc.Driver
- jdbc.url=jdbc:mysql://${_var:MARIADB_SERVICE_HOST}:${_var:MARIADB_SERVICE_PORT}/mydb?serverTimezone=UTC&useSSL=false&autoReconnect=true
- jdbc.username=root
- <bean id="jdbc-properties" class="com.naskar.spring.VariablePropertyPlaceholderConfigurer">
- <property name="location" value="classpath:jdbc#{systemProperties['env']}.properties"/>
- <property name="searchSystemEnvironment" value="true"/>
- <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
- </bean>
- <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
- <property name="driverClassName" value="${jdbc.driverClassName}" />
- <property name="url" value="${jdbc.url}" />
- <property name="username" value="${jdbc.username}" />
- <property name="password" value="${jdbc.password}" />
- </bean>
- class VariablePropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {
- private static String resolveValueWithEnvVars(String value) {
- if (null == value) {
- return null;
- }
- Pattern p = Pattern.compile('\$\{_var:(\w+)\}|\$(\w+)');
- Matcher m = p.matcher(value);
- StringBuffer sb = new StringBuffer();
- while (m.find()) {
- String envVarName = null == m.group(1) ? m.group(2) : m.group(1);
- String envVarValue = System.getProperty(envVarName);
- if(envVarValue == null) {
- envVarValue = System.getenv(envVarName);
- }
- m.appendReplacement(sb, null == envVarValue ? "" : Matcher.quoteReplacement(envVarValue));
- }
- m.appendTail(sb);
- return sb.toString();
- }
- @Override
- protected String convertPropertyValue(String originalValue) {
- return resolveValueWithEnvVars(originalValue);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement