Reputation: 1157
This is confusing. I have a property outerParameter, which is optionaly given among VM options when starting tomcat. I am using it by the following way in my logic:
@Value("${outerParameter:paused}")
private String featureStatus = "active";
public String getFeatureStatus() {
return featureStatus;
}
When starting tomcat without parameter - getFeatureStatus gives "paused", as expected. When starting with defined parameter - gives this parameter value, as expected.
The confusing part is that when I am runing JUnit tests for getFeatureStatus, it anyway gives me "active" and not the default "paused". The context for tests doesn't contain any <context:property-placeholder../>
configuration.
I am trying to understand what I am missing, maybe somebody could give me a hand
I found this: Spring @Value annotation not using defaults when property is not present which could be the answer for my case too. It says "Perhaps initialization of property placeholder configurer fails due to missed properties file, so that placeholders are not resolved". But if so, why it doesn't fail when starting tomcat without defined outerParameter?
Thanks
Upvotes: 1
Views: 5493
Reputation: 5739
It means that the property is not loaded in the test case's classpath. Try loading the properties file in the context for test.
Upvotes: 1