You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently there is support for default values with @Value when using property place holders
@Value("${fee:25}")
private int overdraft;
But this doesn't work with SPeL expressions. While this isn't inherently an issue at this point I think this will be problematic with the new features in Spring 3.1 for the Environment configuration profiles.
public class SpelExpressionDefaultTest {
@Test
public void testSpelDefaultValue() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(
PropertyPlaceholderConfigurer.class, FeeService.class
);
Assert.assertEquals(25, ctx.getBean(FeeService.class).getOverdraft());
}
@Component
public static class FeeService {
@Value("#{systemProperties['fee']:25}")
private int overdraft;
public int getOverdraft() {
return overdraft;
}
}
}
This particular test will fail on a parsing exception from SPeL. This directly relates to #11472 which was closed as invalid as there is a work around to just use ${:default} syntax instead.
If we change the FeeService to
@Component
public static class FeeService {
@Value("${fee:25}")
private int overdraft;
public int getOverdraft() {
return overdraft;
}
}
This will work as expected. SPeL should probably support the default value option especially with the new Environment Profiles coming in 3.1
Daniel Hopper opened SPR-7674 and commented
Currently there is support for default values with
@Value
when using property place holdersBut this doesn't work with SPeL expressions. While this isn't inherently an issue at this point I think this will be problematic with the new features in Spring 3.1 for the Environment configuration profiles.
This particular test will fail on a parsing exception from SPeL. This directly relates to #11472 which was closed as invalid as there is a work around to just use ${:default} syntax instead.
If we change the FeeService to
This will work as expected. SPeL should probably support the default value option especially with the new Environment Profiles coming in 3.1
Affects: 3.0.4
Referenced from: commits f20ded5
The text was updated successfully, but these errors were encountered: