org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'dataSource' defined in class path resource [org/rbram/docpublisher/changeowner/changeOwnerPubApplicationContext.xml]: Could not resolve placeholder '${environment'

Spring JIRA | Robert Mark Bram | 9 years ago
  1. 0

    Also discussed here: http://forum.springframework.org/showthread.php?t=49973 A nested property in Srping config like this: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="ignoreUnresolvablePlaceholders" value="false" /> <property name="location" value="classpath:org/rbram/docpublisher/changeowner/changeowner.properties" /> </bean> <bean name="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" destroy-method="close"> <property name="driverClassName"> <value>${${environment}.dataSource.driverClassName}</value> </property> <property name="url"> <value>${${environment}.dataSource.url}</value> </property> <property name="username"> <value>${${environment}.dataSource.username}</value> </property> <property name="password"> <value>${${environment}.dataSource.password}</value> </property> </bean> </beans> With a property file like this: # Environment: local, dev, test, svt or prod. environment=prod prod.dataSource.url=jdbc:oracle:thin:@(DESCRIPTION=(LOAD_BALANCE=on)(ADDRESS=(PROTOCOL=TCP)(HOST=uporac01vip)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=uporac02vip)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=uporac03vip)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=uporac04vip)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORPCORE.cmltd.net.au))) prod.dataSource.username=DOCPUBLISHER_PROD prod.dataSource.password=wescoles07 prod.dataSource.driverClassName=oracle.jdbc.driver.OracleDriver I get this stack trace: org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'dataSource' defined in class path resource [org/rbram/docpublisher/changeowner/changeOwnerPubApplicationContext.xml]: Could not resolve placeholder '${environment' at org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.processProperties(PropertyPlaceholderConfigurer.java:252) at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:75) at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:542) at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:516)changeowner.DocumentOwnerChangerSpring(139) - Problem running Document Owner Changer. Rolling back. org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'dataSource' defined in class path resource [org/rbram/docpublisher/changeowner/changeOwnerPubApplicationContext.xml]: Could not resolve placeholder '${environment' at org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.processProperties(PropertyPlaceholderConfigurer.java:252) at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:75) at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:542) at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:516) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:348) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:123) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:66) at org.rbram.docpublisher.changeowner.DocumentOwnerChangerSpring.run(DocumentOwnerChangerSpring.java:115) at org.rbram.docpublisher.changeowner.DocumentOwnerChangerSpring.main(DocumentOwnerChangerSpring.java:99) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:348) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:123) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:66) at org.rbram.docpublisher.changeowner.DocumentOwnerChangerSpring.run(DocumentOwnerChangerSpring.java:115) at org.rbram.docpublisher.changeowner.DocumentOwnerChangerSpring.main(DocumentOwnerChangerSpring.java:99) But the parseStringValue() method in PropertyPlaceholderConfigurer indicates that the logic should recursively evaluate nested properties. Setting ignoreUnresolvablePlaceholders to true just leaves me with literal i.e. unresolves values ${${environment}.dataSource.driverClassName} etc..

    Spring JIRA | 9 years ago | Robert Mark Bram
    org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'dataSource' defined in class path resource [org/rbram/docpublisher/changeowner/changeOwnerPubApplicationContext.xml]: Could not resolve placeholder '${environment'
  2. 0

    Also discussed here: http://forum.springframework.org/showthread.php?t=49973 A nested property in Srping config like this: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="ignoreUnresolvablePlaceholders" value="false" /> <property name="location" value="classpath:org/rbram/docpublisher/changeowner/changeowner.properties" /> </bean> <bean name="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" destroy-method="close"> <property name="driverClassName"> <value>${${environment}.dataSource.driverClassName}</value> </property> <property name="url"> <value>${${environment}.dataSource.url}</value> </property> <property name="username"> <value>${${environment}.dataSource.username}</value> </property> <property name="password"> <value>${${environment}.dataSource.password}</value> </property> </bean> </beans> With a property file like this: # Environment: local, dev, test, svt or prod. environment=prod prod.dataSource.url=jdbc:oracle:thin:@(DESCRIPTION=(LOAD_BALANCE=on)(ADDRESS=(PROTOCOL=TCP)(HOST=uporac01vip)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=uporac02vip)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=uporac03vip)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=uporac04vip)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORPCORE.cmltd.net.au))) prod.dataSource.username=DOCPUBLISHER_PROD prod.dataSource.password=wescoles07 prod.dataSource.driverClassName=oracle.jdbc.driver.OracleDriver I get this stack trace: org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'dataSource' defined in class path resource [org/rbram/docpublisher/changeowner/changeOwnerPubApplicationContext.xml]: Could not resolve placeholder '${environment' at org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.processProperties(PropertyPlaceholderConfigurer.java:252) at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:75) at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:542) at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:516)changeowner.DocumentOwnerChangerSpring(139) - Problem running Document Owner Changer. Rolling back. org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'dataSource' defined in class path resource [org/rbram/docpublisher/changeowner/changeOwnerPubApplicationContext.xml]: Could not resolve placeholder '${environment' at org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.processProperties(PropertyPlaceholderConfigurer.java:252) at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:75) at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:542) at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:516) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:348) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:123) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:66) at org.rbram.docpublisher.changeowner.DocumentOwnerChangerSpring.run(DocumentOwnerChangerSpring.java:115) at org.rbram.docpublisher.changeowner.DocumentOwnerChangerSpring.main(DocumentOwnerChangerSpring.java:99) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:348) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:123) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:66) at org.rbram.docpublisher.changeowner.DocumentOwnerChangerSpring.run(DocumentOwnerChangerSpring.java:115) at org.rbram.docpublisher.changeowner.DocumentOwnerChangerSpring.main(DocumentOwnerChangerSpring.java:99) But the parseStringValue() method in PropertyPlaceholderConfigurer indicates that the logic should recursively evaluate nested properties. Setting ignoreUnresolvablePlaceholders to true just leaves me with literal i.e. unresolves values ${${environment}.dataSource.driverClassName} etc..

    Spring JIRA | 9 years ago | Robert Mark Bram
    org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'dataSource' defined in class path resource [org/rbram/docpublisher/changeowner/changeOwnerPubApplicationContext.xml]: Could not resolve placeholder '${environment'
  3. 0

    [SPR-4477] PropertyPlaceholderConfigurer - nested placeholders don't work in placeholder keys - Spring JIRA

    spring.io | 1 year ago
    org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'dataSource' defined in class path resource : Could not resolve placeholder '${environment'
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Spring Circular placeholder reference while running an executable jar

    Stack Overflow | 4 years ago | Shamik
    org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'postProcessProperties' defined in class path resource [applicationContext.xml]: Circular placeholder reference 'processor.core.poolsize' in property definitions

    15 unregistered visitors
    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. org.springframework.beans.factory.BeanDefinitionStoreException

      Invalid bean definition with name 'dataSource' defined in class path resource [org/rbram/docpublisher/changeowner/changeOwnerPubApplicationContext.xml]: Could not resolve placeholder '${environment'

      at org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.processProperties()
    2. Spring Beans
      PropertyResourceConfigurer.postProcessBeanFactory
      1. org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.processProperties(PropertyPlaceholderConfigurer.java:252)
      2. org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:75)
      2 frames
    3. Spring Context
      ClassPathXmlApplicationContext.<init>
      1. org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:542)
      2. org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:516)
      3. org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:348)
      4. org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:123)
      5. org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:66)
      5 frames
    4. org.rbram.docpublisher
      DocumentOwnerChangerSpring.main
      1. org.rbram.docpublisher.changeowner.DocumentOwnerChangerSpring.run(DocumentOwnerChangerSpring.java:115)
      2. org.rbram.docpublisher.changeowner.DocumentOwnerChangerSpring.main(DocumentOwnerChangerSpring.java:99)
      2 frames
    5. Spring Context
      ClassPathXmlApplicationContext.<init>
      1. org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:348)
      2. org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:123)
      3. org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:66)
      3 frames
    6. org.rbram.docpublisher
      DocumentOwnerChangerSpring.main
      1. org.rbram.docpublisher.changeowner.DocumentOwnerChangerSpring.run(DocumentOwnerChangerSpring.java:115)
      2. org.rbram.docpublisher.changeowner.DocumentOwnerChangerSpring.main(DocumentOwnerChangerSpring.java:99)
      2 frames