Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <servlet>
- <servlet-name>spring-web</servlet-name>
- <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
- <load-on-startup>1</load-on-startup>
- <init-param>
- <param-name>contextInitializerClasses</param-name>
- <param-value>com.galapagos.context.CustomEnvironmentApplicationContextInitializer</param-value>
- </init-param>
- </servlet>
- public class CustomEnvironmentApplicationContextInitializer
- implements ApplicationContextInitializer<ConfigurableApplicationContext> {
- private static final Logger logger = LoggerFactory.getLogger(
- CustomEnvironmentApplicationContextInitializer.class);
- @Override
- public void initialize(ConfigurableApplicationContext applicationContext) {
- // Get the environment
- ConfigurableEnvironment environment = applicationContext.getEnvironment();
- try {
- profile = environment.getActiveProfiles()[0];
- String fileName = String.format(
- "database-%s.properties",
- profile);
- ResourcePropertySource resource =
- new ResourcePropertySource(new ClassPathResource(fileName));
- environment.getPropertySources().addFirst(resource);
- logger.info("Loaded: " + resource);
- } catch (IOException e) {
- logger.warn("Error loading: " + e);
- }
- // Print the list of property sources
- logger.info("ENVIRONMENT: " + environment.getPropertySources());
- // Refresh the context - is this even needed??
- applicationContext.refresh();
- }
- }
- 2017-01-29 21:43:25 INFO CustomEnvironmentApplicationContextInitializer:66 - ENVIRONMENT: [class path resource [database-dev.properties],servletConfigInitParams,servletContextInitParams,jndiProperties,systemProperties,systemEnvironment]
- jdbc.driverClassName=org.postgresql.Driver
- jdbc.url=jdbc:postgresql://localhost:5432/galapagos_dev
- jdbc.username=my_user
- jdbc.password=
- <beans:bean
- class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
- </beans:bean>
- <!-- Database / JDBC -->
- <beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
- <beans:property name="driverClassName" value="${jdbc.driverClassName}" />
- <beans:property name="url" value="${jdbc.url}" />
- <beans:property name="username" value="${jdbc.username}" />
- <beans:property name="password" value="${jdbc.password}" />
- </beans:bean>
- 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