Advertisement
Guest User

Untitled

a guest
Jan 30th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. <servlet>
  2. <servlet-name>spring-web</servlet-name>
  3. <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  4. <load-on-startup>1</load-on-startup>
  5. <init-param>
  6. <param-name>contextInitializerClasses</param-name>
  7. <param-value>com.galapagos.context.CustomEnvironmentApplicationContextInitializer</param-value>
  8. </init-param>
  9. </servlet>
  10.  
  11. public class CustomEnvironmentApplicationContextInitializer
  12. implements ApplicationContextInitializer<ConfigurableApplicationContext> {
  13.  
  14. private static final Logger logger = LoggerFactory.getLogger(
  15. CustomEnvironmentApplicationContextInitializer.class);
  16.  
  17.  
  18. @Override
  19. public void initialize(ConfigurableApplicationContext applicationContext) {
  20. // Get the environment
  21. ConfigurableEnvironment environment = applicationContext.getEnvironment();
  22.  
  23. try {
  24.  
  25. profile = environment.getActiveProfiles()[0];
  26.  
  27. String fileName = String.format(
  28. "database-%s.properties",
  29. profile);
  30.  
  31. ResourcePropertySource resource =
  32. new ResourcePropertySource(new ClassPathResource(fileName));
  33.  
  34. environment.getPropertySources().addFirst(resource);
  35. logger.info("Loaded: " + resource);
  36.  
  37. } catch (IOException e) {
  38. logger.warn("Error loading: " + e);
  39. }
  40.  
  41. // Print the list of property sources
  42. logger.info("ENVIRONMENT: " + environment.getPropertySources());
  43.  
  44. // Refresh the context - is this even needed??
  45. applicationContext.refresh();
  46. }
  47.  
  48.  
  49. }
  50.  
  51. 2017-01-29 21:43:25 INFO CustomEnvironmentApplicationContextInitializer:66 - ENVIRONMENT: [class path resource [database-dev.properties],servletConfigInitParams,servletContextInitParams,jndiProperties,systemProperties,systemEnvironment]
  52.  
  53. jdbc.driverClassName=org.postgresql.Driver
  54. jdbc.url=jdbc:postgresql://localhost:5432/galapagos_dev
  55. jdbc.username=my_user
  56. jdbc.password=
  57.  
  58. <beans:bean
  59. class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  60. </beans:bean>
  61.  
  62. <!-- Database / JDBC -->
  63.  
  64. <beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
  65. <beans:property name="driverClassName" value="${jdbc.driverClassName}" />
  66. <beans:property name="url" value="${jdbc.url}" />
  67. <beans:property name="username" value="${jdbc.username}" />
  68. <beans:property name="password" value="${jdbc.password}" />
  69. </beans:bean>
  70.  
  71. Could not resolve placeholder 'jdbc.driverClassName' in string value "${jdbc.driverClassName}"; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'jdbc.driverClassName' in string value "${jdbc.driverClassName}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement