0

I'm using the property file to configure the datasource in spring :

<bean id="mydataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
        destroy-method="close">
        <property name="driverClass" value="${database.driver}" />
        <property name="jdbcUrl" value="${database.url}" />
        <property name="user" value="${database.username}" />
        <property name="password" value="${database.password}" />
         <property name="initialPoolSize" value="${database.initialpoolsize}" 
            />
         <property name="minPoolSize" value="${database.minpoolsize}" /> 
         <property name="maxPoolSize" value="${database.maxpoolsize}" /> 

    </bean>

Here is the configuration of this file in spring

<context:property-placeholder location="classpath*:database.properties" />

This property file is under src/test/config/ folder , when I run the test it gives me this error:

java.lang.IllegalArgumentException: Could not resolve placeholder 'database.driver' in string value "${database.driver}"

Could someone help me on that?

2
  • move it to src/main/resources/, that is what gets added to classpath, if this is just for test purpose then move it to src/test/resources/ Jun 29, 2015 at 1:06
  • yes I have moved it to src/test/resources and it's working but for that project I must follow this practise (based on other projects) so I don't know if I must add some configuration on maven?
    – codeDev
    Jun 29, 2015 at 1:19

1 Answer 1

0

resources placed in src/main/resources would be available to runtime classpath, as they get copied over to target/classes by resource plugin, if you want the properties file specific to test classes then it should be placed under src/test/resources

If you want to place it under src/test/config

<project>
 ...
 <build>
   ...
   <resources>
     <resource>
       <directory>src/test/config</directory>
     </resource>
   </resources>
   ...
 </build>
 ...
</project>
2
  • And if I want to put this property file under src/test/config is that possible?
    – codeDev
    Jun 29, 2015 at 1:28
  • I have added that config on pom.xml with this config in spring : <context:property-placeholder location="classpath*:database.properties" />but it didn't work
    – codeDev
    Jun 29, 2015 at 1:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.