Ramesh
Ramesh

Reputation: 633

Could not resolve placeholder for context:property-placeholder

I am trying to set my app to use different data source definitions, based on an environment variable, but I'm running into the below error. I looked at many similar questions, but they don't seem to be the same.

I have set up multiple properties files:

env-dev.properties
env-test.properties
env-prod.properties
env-.properties

I have created a system property called MEM_ENV with the value "dev"

My spring xml file looks like this:

    <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:jee="http://www.springframework.org/schema/jee"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
    <context:property-placeholder
        location="classpath*:*env-${MEM_ENV}.properties" />
    <bean id="mongoDataSource" class="com.iLearn.persistence.base.MongoDataSourceImpl">
        <property name="server" value="${mongo.server}" />
        <property name="port" value="${mongo.port}" />
        <property name="dbName" value="${mongo.dbName}" />
        <property name="userName" value="${mongo.userName}" />
        <property name="password" value="${mongo.password}" />
    </bean>

My properties files look like this:

mongo.server=aServer.com
mongo.port=10003
monog.dbName=aDBName
mongo.userName=aUserName
mongo.password=aPassword

The exception I'm getting is:

    message org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'mongoDataSource' defined in class path resource [springAppConfig.xml]: Could not resolve placeholder 'mongo.server' in string value "${mongo.server}"

description The server encountered an internal error (org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'mongoDataSource' defined in class path resource [springAppConfig.xml]: Could not resolve placeholder 'mongo.server' in string value "${mongo.server}") that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'mongoDataSource' defined in class path resource [springAppConfig.xml]: Could not resolve placeholder 'mongo.server' in string value "${mongo.server}"
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:606)
    org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:357)
    com.iLearn.security.AccessFilter.doFilter(AccessFilter.java:43)

Upvotes: 0

Views: 14773

Answers (2)

Ramesh
Ramesh

Reputation: 633

It seems that the system variable didn't work until I rebooted my machine. After that it worked fine, (once I fixed my typo of monog.dbName).

I'm not sure if it was the reboot of Windows, or the restart of Eclipse, or restart of Tomcat that fixed the problem, as all of those occurred with my reboot.

Hope this helps someone else - if you have this problem, first try a reboot.

Upvotes: 1

Jayamohan
Jayamohan

Reputation: 12924

You have used the classpath resolver wrongly. Remove one unnecessay *.

Change from,

<context:property-placeholder location="classpath*:*env-${MEM_ENV}.properties" />

to

<context:property-placeholder location="classpath*:env-${MEM_ENV}.properties" />

Upvotes: 1

Related Questions