Advertisement
Guest User

Untitled

a guest
Oct 12th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1. <context:component-scan base-package="org.dhana.*" />
  2.  
  3. <context:annotation-config />
  4.  
  5. <bean id="transactionManager"
  6. class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  7. <property name="dataSource" ref="dataSource" />
  8. </bean>
  9.  
  10.  
  11.  
  12. <bean id="dataSource"
  13. class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  14. <property name="driverClassName" value="com.mysql.jdbc.Driver" />
  15. <property name="url"
  16. value="xxxx" />
  17. <property name="username" value="${db_username}" />
  18. <property name="password" value="xxxxx" />
  19. </bean>
  20.  
  21. <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
  22. <property name="dataSource" ref="dataSource" />
  23. </bean>
  24.  
  25. <bean id="propertyPlaceholderConfigurer"
  26. class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  27. <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
  28. <property name="searchSystemEnvironment" value="true" />
  29. </bean>
  30.  
  31. value="#{systemProperties['db_username']}"
  32.  
  33. <context:property-placeholder location="file:${env_config_path}/configuration.properties" />
  34.  
  35. -Denv_resource_path="/Users/mylogin/work/myproject/development_environment_resources"
  36.  
  37. jdbc.userName = xxx
  38. jdbc.password = yyy
  39.  
  40. <bean id = "prop"
  41. class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  42. <property name="locations">
  43. <value>classpath*:xxxx.properties</value>
  44. </property>
  45.  
  46. <bean id="dataSource"
  47. class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  48. <property name="driverClassName" value="${}"/>
  49. <property name="url" value="${}"/>
  50. <property name="username" value="${jdbc.userName}"/>
  51. <property name="password" value="${jdbc.password}"/> </bean>
  52.  
  53. jdbc.driverClassName=com.mysql.jdbc.Driver
  54. jdbc.url=jdbc:mysql://${_var:MARIADB_SERVICE_HOST}:${_var:MARIADB_SERVICE_PORT}/mydb?serverTimezone=UTC&useSSL=false&autoReconnect=true
  55. jdbc.username=root
  56.  
  57. <bean id="jdbc-properties" class="com.naskar.spring.VariablePropertyPlaceholderConfigurer">
  58. <property name="location" value="classpath:jdbc#{systemProperties['env']}.properties"/>
  59. <property name="searchSystemEnvironment" value="true"/>
  60. <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
  61. </bean>
  62.  
  63. <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
  64. <property name="driverClassName" value="${jdbc.driverClassName}" />
  65. <property name="url" value="${jdbc.url}" />
  66. <property name="username" value="${jdbc.username}" />
  67. <property name="password" value="${jdbc.password}" />
  68. </bean>
  69.  
  70. class VariablePropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {
  71.  
  72. private static String resolveValueWithEnvVars(String value) {
  73. if (null == value) {
  74. return null;
  75. }
  76.  
  77. Pattern p = Pattern.compile('\$\{_var:(\w+)\}|\$(\w+)');
  78. Matcher m = p.matcher(value);
  79. StringBuffer sb = new StringBuffer();
  80.  
  81. while (m.find()) {
  82. String envVarName = null == m.group(1) ? m.group(2) : m.group(1);
  83. String envVarValue = System.getProperty(envVarName);
  84. if(envVarValue == null) {
  85. envVarValue = System.getenv(envVarName);
  86. }
  87. m.appendReplacement(sb, null == envVarValue ? "" : Matcher.quoteReplacement(envVarValue));
  88. }
  89.  
  90. m.appendTail(sb);
  91.  
  92. return sb.toString();
  93. }
  94.  
  95. @Override
  96. protected String convertPropertyValue(String originalValue) {
  97. return resolveValueWithEnvVars(originalValue);
  98. }
  99.  
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement