Failed to resolve placeholder | Spring Placeholder

I am trying to use Spring <context:property-placeholder>in my application for the first time and having encountered some problems, I have already tried many things, and already Google and it seems that several posts are over SO.

I have a web application and need to pass some keys to the base class, I thought about using the owner’s place for this. Here is the structure of my application

Main
  -java
  -resources
  -webapp

I have a file project.propertiesthat is inside a folder resource, this is how I try

<context:property-placeholder location="classpath:resources/project.properties" />
<beans:bean id="reCaptcha" class="net.tanesha.recaptcha.ReCaptchaImpl">
  <beans:property name="privateKey" value="${demo.recapatcha_private_key}"/>
   <beans:property name="publicKey" value="${demo.recapatcha_public_key}"/>
</beans:bean>

But I get the following exception when starting the server

org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'reCaptcha' defined in ServletContext resource [/WEB-INF/spring/appServlet/servlet-context.xml]: Could not resolve placeholder 'demo.recapatcha_private_key'

I have already tried placing the project.properties file in another place, which includes WEB-INF/classesseveral other places in webapp, but without success. Not sure what I'm doing wrong

+4
1

, Maven. project.properties src/main/resources - Maven , /WEB-INF/classes .

location <context:property-placeholder> resources. resources /WEB-INF/classes - . .

<context:property-placeholder location="classpath:project.properties" />
+6

Source: https://habr.com/ru/post/1524325/


All Articles