Vivek Kumar
Vivek Kumar

Reputation: 407

Getting "Could not resolve placeholder in string value"

I am using Jboss 6 for deploying the project. What i want is to have a datasource.properties file and using that file to define datasource bean. I did this but get error that "Could not resolve placeholder in string value".

My datasource.properties file is placed inside config module jboss folder.

and in my application context i have added

<bean
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

        <property name="location">
            <value>classpath:datasource.properties</value>
        </property>
    </bean>

bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">

        <property name="driverClassName" value="${jdbc.driverClassName}" />
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
    </bean>

This is my datasource.properties file

jdbc.driverClassName=com.mysql.jdbc.Driver
    jdbc.url=jdbc:mysql://localhost:3306/mkyongjava
    jdbc.username=root
    jdbc.password=password

Any help will be appreciated.

Upvotes: 0

Views: 4633

Answers (1)

Sundararaj Govindasamy
Sundararaj Govindasamy

Reputation: 8495

Place your properties file under src/main/resources and try again.

=====================================

Below reference was taken from this article. which may help.

8. Properties in Parent-Child Contexts

This question keeps coming up again and again – what happens when you web application has a parent and a child context? The parent context may have some common core functionality and beans, and then one (or multiple) child contexts, maybe containing servlet specific beans. In that case, what’s the best way to define properties files and include them into these contexts? What’s more – how to best retrieve these properties form Spring? Here is the simple breakdown.

8.1. If the properties file is defined in XML with

If the file is defined in the Parent context:

@Value works in Child context: NO

@Value works in Parent context: YES

If the file is defined in the Child context:

@Value works in Child context: YES

@Value works in Parent context: NO

Finally, as we discussed before, does not expose the properties to the environment, so:

environment.getProperty works in either context: NO

Upvotes: 1

Related Questions