如结构:
proName
   src 
      applicationContext.xml
       
   config
      config.properties  在applicationContext中怎么加载不是在src目下的配置文件,config在这里只是一个文件夹
     

解决方案 »

  1.   

    xml中配置 
    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
      <property name="locations">
      <list>
      <value>classpath:config.properties</value>
      </list>
      </property>
    </bean>
      

  2.   

    spring 3.x
    <context:property-placeholder location="classpath*:config/*.properties" />spring 2.5.x
    <bean id="placeHolder"  
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
        <property name="locations">  
            <list>  
                <value>classpath:config/config.properties</value>  
            </list>  
        </property>  
    </bean> 
      

  3.   

    误点了发帖,蛋疼。
    我上面的帖子请忽略。2.5.6<bean id="placeHolder"  
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
        <property name="locations">  
            <list>  
                <value>file:config/config.properties</value>  
            </list>  
        </property>  
    </bean> 
    3.0.5<context:property-placeholder location="file:config/file.properties" />
      

  4.   

    ls是一种做法,不过还有一种更通用的做法,不仅针对spring。即程序需要读取的资源,不在默认的src(其实是classpath下)
    如果不是特意把放到classpath外面去的话,可以在工程中,把config也设置为src目录,或者在jvm中添加classpath,指向config目录。