I have an application where a property placeholder is used to read properties, configured in applicationContext.xml
:
...
<context:property-placeholder
location="classpath*:META-INF/spring/*.properties"/>
...
The application runs in an Tomcat and uses the parameter defined in context.xml.
The application access this parameter like normal properties (@Value(${cfma.applicationUrl})
). This works
In my test cases I do not have this tomcat properties, so I want to add them "manually" to the application context. But also load the normal applicationContext.xml
testContext.xml:
<import resource="classpath:/META-INF/spring/applicationContext.xml" />
<context:property-placeholder properties-ref="simulatedTomcatProperties"/>
<util:properties id="simulatedTomcatProperties">
<prop key="cfmt.applicationBaseUrl">localhost:8080/cfmt</prop>
</util:properties>
Now I have two context:property-placeholder and this does not work (of course) – So my question is, who can I extend the properties in the “normal” property-placeholder in my test?
More Explanation of what I need:
@Value(${cfma.applicationUrl})
). Moreover there must not be any Fallback, if the properties are not defined in the Tomcat, the application must not start!context:property-placeholder
they are not merged:@See Comments on https://jira.springsource.org/browse/SPR-4881 -- they explain that behaviour.
When I talk about Tomcat parameter I am talking about somethink like this:
context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Parameter name="cfmt.applicationBaseUrl"
value="http://localhost/demoApp" override="false"/>
</Context>
The context:property-placeholder tag is used to externalize properties in a separate file. It automatically configures PropertyPlaceholderConfigurer , which replaces the ${} placeholders, which are resolved against a specified properties file (as a Spring resource location).
Secure Property Placeholder is an important standard for keeping our sensitive data like User ID and Password secure (encrypted/cypher-text) in the Property file. Data is stored in the property file as key value pair. This property file can store information like User ID, Password, Tokens, Keys etc.
Just use: final var configurer = new PropertySourcesPlaceholderConfigurer(); configurer. setProperties(properties);
A property resource configurer that resolves placeholders in bean property values of context definitions. It pulls values from a properties file into bean definitions. The default placeholder syntax follows the Ant / Log4J / JSP EL style: ${...}
Not sure if this will help, but what I do in a similar situation is have 2 app.properties files with the same name, one in sec/test/resources and the other in src/main/resources. Now during testing the first is loaded because the test classes are first on the classpath, but when I deploy only the main one is there and so it is loaded.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With