Hi,
According to the docs this works.
However accessing system properties programmatically in SpEL does not work.Code:<bean id="taxCalculator" class="org.spring.samples.TaxCalculator"> <property name="defaultLocale" value="#{ systemProperties['user.region'] }"/> </bean>
What obvious piece of information am I missing? Is this predefined variable only registered on context load and if using programmatically this is something I have to register by myself?Code:@Test public void testGetSystemProperty() { System.setProperty("foo", "bar"); ExpressionParser parser = new SpelExpressionParser(); Expression exp = parser.parseExpression("systemProperties['foo']"); String value = exp.getValue(String.class); assertEquals("bar", value); }
Works but not quite the same :)Code:@Test public void testGetSystemProperty() { System.setProperty("foo", "bar"); EvaluationContext context = new StandardEvaluationContext(); context.setVariable("systemProperties", System.getProperties()); ExpressionParser parser = new SpelExpressionParser(); Expression exp = parser.parseExpression("#systemProperties['foo']"); String value = exp.getValue(context, String.class); assertEquals("bar", value); }
Thanks.


Reply With Quote
