spring-el

Spring Expression Language (SpEL) with @Value: dollar vs. hash ($ vs. #)

a 夏天 提交于 2019-11-27 05:58:55
I'm a little confused concerning when to use ${...} compared to #{...} . Spring's documentation only uses #{...} , but there are plenty of examples that use ${...} . Furthermore, when I started with SpEL I was told to use ${...} and it works fine. For those who are confused, an example of how I use it would be @Component public class ProxyConfiguration { @Value("${proxy.host}") private String host; @Value("${proxy.port}") private String port; : } and some property file: proxy.host=myproxy.host proxy.port=8000 My questions are: what are the differences or is it the same? is one version

Spring Boot SpEL ConditionalOnExpression check multiple properties

强颜欢笑 提交于 2019-11-27 02:26:58
问题 Question: How can I use Spring Expression Language to check that 2 Boolean properties are true? For example, checking that a single property is true would use the syntax: Example @ConditionalOnExpression("${property.from.properties.file}") What would be the syntax for checking property1 == true && property2 == false ? Where the properties can potentially have different values. The answer from a similar question: How to check two condition while using @ConditionalOnProperty or

How to JUnit tests a @PreAuthorize annotation and its spring EL specified by a spring MVC Controller?

霸气de小男生 提交于 2019-11-27 01:57:34
问题 I've defined this method in my Spring MVC Controller : @RequestMapping(value = "{id}/content", method=RequestMethod.POST) @PreAuthorize("principal.user.userAccount instanceof T(com.anonym.model.identity.PedagoAccount) AND principal.user.userAccount.userId == #object.pedago.userId AND #form.id == #object.id") public String modifyContent(@PathVariable("id") Project object, @Valid @ModelAttribute("form") ProjectContentForm form) { .... } Then in my JUnit test I'd like to call this method and

Concatenate multiple node values in xpath

耗尽温柔 提交于 2019-11-27 01:32:35
I have a XML that looks like this <element1> <element2> <element3> <element4>Hello</element4> <element5>World</element5> </element3> <element3> <element4>Hello2</element4> <element5>World2</element5> </element3> <element3> <element4>Hello3</element4> <element5>World3</element5> </element3> </element2> </element1> I am trying to use Xpath to get a result like this: Hello.World Hello2.World2 Hello3.World3 I used concat function below but I did not get correct result. Concat function: concat(/element1/element2/element3/element4/text(),".", /element1/element2/element3/element5/text()) Result I got

Spring Expression Language (SpEL) with @Value: dollar vs. hash ($ vs. #)

心已入冬 提交于 2019-11-26 11:48:07
问题 I\'m a little confused concerning when to use ${...} compared to #{...} . Spring\'s documentation only uses #{...} , but there are plenty of examples that use ${...} . Furthermore, when I started with SpEL I was told to use ${...} and it works fine. For those who are confused, an example of how I use it would be @Component public class ProxyConfiguration { @Value(\"${proxy.host}\") private String host; @Value(\"${proxy.port}\") private String port; : } and some property file: proxy.host

Concatenate multiple node values in xpath

六月ゝ 毕业季﹏ 提交于 2019-11-26 09:41:23
问题 I have a XML that looks like this <element1> <element2> <element3> <element4>Hello</element4> <element5>World</element5> </element3> <element3> <element4>Hello2</element4> <element5>World2</element5> </element3> <element3> <element4>Hello3</element4> <element5>World3</element5> </element3> </element2> </element1> I am trying to use Xpath to get a result like this: Hello.World Hello2.World2 Hello3.World3 I used concat function below but I did not get correct result. Concat function: concat(

How to fill HashMap from java property file with Spring @Value

无人久伴 提交于 2019-11-26 04:47:30
问题 Is it possible to use Spring @Value, to map values from properties file to the HashMap. Currently I have something like this, and mapping one value is not a problem. But I need to map custom values in HashMap expirations. Is something like this possible? @Service @PropertySource(value = \"classpath:my_service.properties\") public class SomeServiceImpl implements SomeService { @Value(\"#{conf[\'service.cache\']}\") private final boolean useCache = false; @Value(\"#{conf[\'service.expiration.[