spring-el

Spring Boot - How to disable @Cachable during development?

二次信任 提交于 2019-11-28 23:19:47
I'm looking for 2 things: How to disable all caching during development with Spring boot "dev" profile. There doesn't seam to be a general setting to turn it all off in application.properties. What's the easiest way? How to disable caching for a specific method? I tried to use SpEl like this: @Cacheable(value = "complex-calc", condition = "#{${spring.profiles.active} != 'dev'}") public String someBigCalculation(String input){ ... } But I can get it to work. There are a couple of questions on SO related to this, but they refer to XML config or other things, but I'm using Spring Boot 1.3.3 and

How do I get a property value from an ApplicationContext object? (not using an annotation)

流过昼夜 提交于 2019-11-28 22:24:31
If I have: @Autowired private ApplicationContext ctx; I can get beans and resources by using one of the the getBean methods. However, I can't figure out how to get property values. Obviously, I can create a new bean which has an @Value property like: private @Value("${someProp}") String somePropValue; What method do I call on the ApplicationContext object to get that value without autowiring a bean? I usually use the @Value, but there is a situation where the SPeL expression needs to be dynamic, so I can't just use an annotation. In the case where SPeL expression needs to be dynamic, get the

Spring Boot SpEL ConditionalOnExpression check multiple properties

為{幸葍}努か 提交于 2019-11-28 08:38:49
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 @ConditionalOnExpression concatenates two strings together and performs a check like so: Concatenation Solution

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

独自空忆成欢 提交于 2019-11-28 07:43:50
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 ensure that the PreAuthorize condition is verified. But when I set the user principal in my JUnit test

Spring - SpEL evaluates entity argument as null reference in @PreAuthorize(“hasPermission”)

[亡魂溺海] 提交于 2019-11-28 05:37:25
问题 I've got problem that SpEL is evaluating entity argument as null reference in the second method of this repository. This first method works well and id is correctly evaluated to Long as should be. @NoRepositoryBean public interface SecuredPagingAndSortingRepository<T extends AuditedEntity, ID extends Serializable> extends PagingAndSortingRepository<T, ID> { @Override @RestResource(exported = false) @PreAuthorize("hasPermission(#id, null, 'owner')") void delete(ID id); @Override @PreAuthorize(

Can Spring evaluate all characters/expressions in SpEL expressions as they are injected from a property file?

拈花ヽ惹草 提交于 2019-11-28 05:11:18
问题 I wonder why spring doesn't directly evaluate all expressions as they are injected from a property file into @PreAuthorize(...) annotation. I think spring doesn't evaluate some characters like '(', ')', ''', etc or it adds special characters on top of those injected values from property file. To clarify, let us consider the following example. @PreAuthorize("hasRole('ROLE_ADMIN')") The above expression is normal, and works fine. Suppose values of the property file are the following. role1=ROLE

List of Spring EL Variables?

寵の児 提交于 2019-11-27 18:37:08
问题 Spring EL supports a some predefined variables {#systemProperties. ... } {#systemEnvironment. ... } {#request. ...} {#session. ...} The first two once are documented in the Spring Reference: chapter 6. Spring Expression Language (SpEL). The two others are not mentioned in the Spring Reference (or I did not found them.) (I found them in this slides, as well as its usage in spring social and this question). So my question is: is there a more or less complete list of predefined spring-el

Spring Boot - How to disable @Cachable during development?

元气小坏坏 提交于 2019-11-27 14:42:46
问题 I'm looking for 2 things: How to disable all caching during development with Spring boot "dev" profile. There doesn't seam to be a general setting to turn it all off in application.properties. What's the easiest way? How to disable caching for a specific method? I tried to use SpEl like this: @Cacheable(value = "complex-calc", condition = "#{${spring.profiles.active} != 'dev'}") public String someBigCalculation(String input){ ... } But I can get it to work. There are a couple of questions on

How do I get a property value from an ApplicationContext object? (not using an annotation)

≡放荡痞女 提交于 2019-11-27 14:18:28
问题 If I have: @Autowired private ApplicationContext ctx; I can get beans and resources by using one of the the getBean methods. However, I can't figure out how to get property values. Obviously, I can create a new bean which has an @Value property like: private @Value("${someProp}") String somePropValue; What method do I call on the ApplicationContext object to get that value without autowiring a bean? I usually use the @Value, but there is a situation where the SPeL expression needs to be

How does Spring 3 expression language interact with property placeholders?

梦想的初衷 提交于 2019-11-27 11:11:56
Spring 3 has introduced a new expression language (SpEL) which can be used in bean definitions. The syntax itself is fairly well specified. What isn't clear is how, if at all, SpEL interacts with the property placeholder syntax that was already present in prior versions. Does SpEL have support for property placeholders, or do I have to combine the syntax of both mechanisms and hope they combine? Let me give a concrete example. I want to use the property syntax ${x.y.z} , but with the addition of "default value" syntax as provided by the elvis operator to handle cases where ${x.y.z} is