Search code examples
springanteclipse-juno

Can't load property file for property-placeholder


my property file is under the following path:

src\main\resources\META-INF\app-config.properties

and my spring configuration files are under the path:

WebContent\WEB-INF

and when trying to load the property file as follows:

<context:property-placeholder
        location="classpath:META-INF/app-config.properties" />

i am getting the exception:

java.io.FileNotFoundException: class path resource [META-INF/app-config.properties] cannot be opened because it does not exist

applicationContext.xml

<?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:aop="http://www.springframework.org/schema/aop"
    xmlns:cache="http://www.springframework.org/schema/cache"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee"
    xmlns:jms="http://www.springframework.org/schema/jms" xmlns:jpa="http://www.springframework.org/schema/data/jpa"
    xmlns:lang="http://www.springframework.org/schema/lang" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:oxm="http://www.springframework.org/schema/oxm" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:task="http://www.springframework.org/schema/task" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:util="http://www.springframework.org/schema/util"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
        http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.1.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
        http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
        http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-3.0.xsd
        http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.1.xsd
        http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.1.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
        http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd
        http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">

    <import resource="application-Security-Context.xml" />

    <import resource="application-DataAccess-Context.xml" />

    <import resource="application-Service-Context.xml" />

    <context:component-scan base-package="com.myapp" />

    <!-- PERSISTENCE -->
    <context:property-placeholder
        location="classpath:META-INF/app-config.properties" />


    <jee:jndi-lookup id="appDS" jndi-name="MyApp" expected-type="javax.sql.DataSource"/>

    <bean id="persistenceUnitManager"
        class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
        <property name="defaultDataSource" ref="appDS" />
    </bean>

    <bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="persistenceUnitManager" ref="persistenceUnitManager" />
        <property name="persistenceUnitName" value="MyApp" />
    </bean>

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>


    <tx:annotation-driven transaction-manager="transactionManager" />
</beans>

applicationContext is loaded in web.xml as follows:

<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>

i am using ant to build my project, am i missing ant configuration or eclipse configuration for this issue ?

ant config:

<zipfileset dir="${basedir}/src/main/resources/META-INF" includes="app-config.properties" fullpath="WEB-INF/classes/META-INF/app-config.properties"/>

also i added the META-INF folder to the deployment assembly in eclipse.

please advise how to load this property file correctly.


Solution

  • Can u try <context:property-placeholder location="classpath*:META-INF/app-config.properties" /> If this also fails then may be your src\main\resources is not under the classpath.