spring-el

Spring @Cacheable with SpEL key: always evaluates to null

冷暖自知 提交于 2019-12-30 11:17:31
问题 I am having a problem with @Cacheable and using a custom key based on Spring expression language. I have the following code @Cacheable(value = "myCache", key = "#providerDTO.identifier") ClientVO loadClientVOByProviderDTO(ProviderDTO providerDTO); This is throwing the following error org.springframework.expression.spel.SpelEvaluation Exception: EL1007Epos 0): Field or property 'identifier' cannot be found on null The providerDTO argument is not null, I have verified this many times. The docs

MongoDB and SpEL Expressions in @Document annotations

五迷三道 提交于 2019-12-30 07:32:29
问题 I am trying to use the SpEL to load the same Document into different collections based on some rules that i have defined. So to start with what i have: -first of all the document: @Document(collection = "#{@mySpecialProvider.getTargetCollectionName()}") public class MongoDocument { // some random fields go in } -second i have the provider bean that should provide the collection name: @Component("mySpecialProvider") public class MySpecialProvider { public String getTargetCollectionName() { //

SpelEvaluationException: EL1007E:(pos 43): Field or property 'group' cannot be found on null

Deadly 提交于 2019-12-30 04:37:07
问题 I have SPRING METHOD security fully configured for my web application. (with PRE/POST annotations enabled). However recently I encountered a strange issue with them. Summary as follows: Summary of POJOS // User Class public class User { int id; String name; // getters and setters } // Group Class public class Group { int id; String name; // getters and setters } // GroupMembership class public class GroupMembership { private int id; private User user; private Group group; // getters and

Spring xml dynamic property placeholder construction

北城以北 提交于 2019-12-25 04:07:00
问题 I would like to dynamically construct a property value expression, as in <property name="server" value="#{'${host}' + {systemProperties['myEnv']}}" /> Let's say the property host exists in a property file aand it's value is 'myserver.net' and the system property myEnv has been set to 'UAT', then this expression results in a value of 'myserver.netUAT'. What I would like if for the whole lot to be evaluated after the concatenation. Right now it's looking up {host} key then appending the

Spring: What parser to use to parse security expressions

喜夏-厌秋 提交于 2019-12-24 21:42:29
问题 I would like to parse standard security expressions like hasRole etc. to get their value in a variable (in a JSP). How can I do that? SpelExpressionParser is the standard EL parser, but I don't think it will parse the security expression. 回答1: The simpliest approach is to use a <sec:authorize> tag and modify a desired variable inside its body. If you actually want to evaluate expressions manually, look at the source of AuthorizeTag - it gets the first bean of type WebSecurtyExpressionHandler

select context variables properties based on other variables in thymeleaf (dynamically)

五迷三道 提交于 2019-12-24 04:17:08
问题 I am a beginner in using Thymeleaf. I have an object which is set as a context variable. ctx.setVariable("name", myObject); this object has several properties, but I can't just select them using `name.property1.subproperty1' because at some point I want to render name.property1.subproperty and name.property2.subproperty in the same template, and I don't want to hardcode this selection in the template because it might change. I was thinking to declare another context variable like: String[]

How to put “new line” in Spring Expression Language?

风格不统一 提交于 2019-12-24 03:38:06
问题 What would be the exact SpEL expression to go to the new line. Here is my configuration: <logging-channel-adapter id="log" channel="loggingChannel" level="INFO" expression="'DealId: '+ payload.dealId \n + 'Name: '+ payload.name" /> 回答1: You can use this as a work-around: <int:logging-channel-adapter id="loggingChannel" logger-name="tapInbound" expression="'DealId: '+ payload.dealId + T(System).getProperty('line.separator') + 'Name: '+ payload.name" level="INFO" /> EDIT: Just to clarify, SpEL

Spring Security method rules: returned value contains a Collection

£可爱£侵袭症+ 提交于 2019-12-24 03:31:01
问题 In Spring Security I want to secure a method incorporating returned values and using @PostAuthorize . I want to add a constraing that will not allow one user to access to resources they are not owners. The problem I face is that I want to check principal id against one collection of values. Scenario: Domain objects: public class Car implements Serializable { private Integer id; private Collection<Driver> drivers; ... } public class Driver implements Serializable { private Integer id; ... }

How to use SpEL to inject result of method call in Spring?

故事扮演 提交于 2019-12-24 00:09:08
问题 I want to inject result of method call to my class. I have next code: class Example { private static final String NAME = "name"; // #1 @Autowired @Qualifier("a.b") private B b; // #2 @Autowired @Qualifier("#{a.b}") private B b; // #3 @Autowired @Qualifier("#{a.b.getC('" + NAME + "')}") private C c; } So I have 3 different variants. First one is working, second one is not working but not sure whether I wrote SpEL correctly and third one is not working too. Actually what I need is third variant

Spring Integration combine path variables and post body in payload expression

旧城冷巷雨未停 提交于 2019-12-23 13:05:34
问题 Using an http inbound-gateway I am able to specify a payload-expression using SPEL that will access header, requestParams, and pathVariables. How do I also include the body from a POST? An example of what I currently have is <int-http:inbound-gateway path="/document/{product}/{id}/blah" supported-methods="GET" request-channel="documentService.blah" reply-channel="httpReplyChannel" message-converters="jsonMessageConverter" header-mapper="defaultHttpHeaderMapper" payload-expression="new