Questions tagged [spring-el]

1

votes
1

answer
205

Views

SpEL are not read in @Query after Spring Boot 2.0.0 M7 update

I had my Spring Boot 2.0.0 M3 application developed. Everything worked just fine. But after updating to Spring Boot 2.0.0 M7 (or even to Spring Boot 2.0.0 M5 more recently) SpELs in my @Query are not longer compiled properly. For example @Query('SELECT m FROM com.mypackage.models.Model m WHERE m.st...
Serg Vasylchak
1

votes
1

answer
256

Views

How do I programmatically read/parse yml values using Spring Boot's SPEL?

If I have an annotation where people can set an SPEL expression (it might have yaml/environment values), how would I parse this to find the actual values? Example: public @interface TestA { String spel() default ''; } @TestA( spel = '${some.value.in.app.yml}' ) public class Test {} The application.y...
Don Rhummy
1

votes
1

answer
846

Views

How to test Spring @Cacheable using customized key with SpEL

I was looking for a way to test some of my @Cacheable and @CacheEvict methods and I've found out a very good explanation here. However, my case is a bit different and trickier. So, using the code from that post as example, I've added a cache key using spEL: interface MyRepo { @Cacheable(value = 'sam...
Reginaldo Santos
1

votes
1

answer
131

Views

In clause parameters with SPEL

I'm trying to pass multiple In Clause parameters using Spring-El, my query is: @Query(nativeQuery = true, value = 'select a.* from ACC a where (a.iban, a.currency) in (:#{#ibanAccounts.accountNumber} , :#{#ibanAccounts.currency})') List getAccount(@Param('ibanAccounts') List ibanAccounts); But I'm g...
oOXAam
1

votes
1

answer
254

Views

Reference current bean with SpEL

Is there a way to reference the current instance of the object which contains the SPeL expression? I am basically looking for something like @Value('#{otherBean.getClassName(this.GetClass())}') Where getClassName(Class class) returns the name of the class, for example.
Dan Markhasin
1

votes
1

answer
798

Views

Spring Boot Properties - Why am I getting the error EL1041E: After parsing a valid expression, there is still more data in the expression 'hash(#)'

I have added a properties file in my Spring boot application which I am using to initialize some values for my program. This is working for simple values, and some slightly more complicated ones, like the examples I have created for value.a and value.b shown below. my.value.a=a my.value.b=b value.a...
Jon
1

votes
1

answer
742

Views

Property or field 'isLPG' cannot be found on object of type 'com.rentautosofia.rentacar.bindingModel.CarBindingModel' - maybe not public?

I have an MVC logic like this one. CarBindingModel package com.rentautosofia.rentacar.bindingModel import javax.validation.constraints.Size class CarBindingModel(@Size(min = 1) var name: String = '', @Size(min = 1) var price: Int = 0, @Size(min = 1) var imgURL: String = '', var isLPG: Boolean? = fal...
Denis Barzanov
0

votes
0

answer
3

Views

Accessing nested headers with Spring Expression Language (SpEL)

My Camel route needs to access kafka.HEADERS headers from the inbound exchange object. One of the headers is further a List of headers wherein value type is RecordHeader. I want to access one of the RecordHeader (e.g. leadEquipmentId) and compare it with a String. Please can someone suggest how to d...
Rajnish Jain
1

votes
2

answer
102

Views

How to use SpEL to select and return root objects in a collection by evaluating a list of other sub-objects maintained in a field in the root objects

The service I'm working with is running in Java 8. I am using SpEL to filter a generic collection of objects based on an input expression. I am successfully filtering the collection when the expression evaluates top-level, primitive fields in the RootObject. The SpEL Collection Selection feature ret...
BZude
1

votes
0

answer
27

Views

Can SpEL be passed an enviroment variable directly or is a properties file in some form always required?

We build micro services and I am working on a generic way of generating documentation for them. This has created a situation where I need to set a variable which is static across all our services yet has two possible values depending on the environment the service is deployed in. Hence I would like...
Anders
1

votes
1

answer
184

Views

What is the Spinnaker pipeline expression for the current stage?

I'm trying to write a Spinnaker pipeline expression that determines some criteria based on the current stage and its ancestors. Per the documentation, you can use the #root helper to get the current stage context; however, it doesn't appear there is any way to get the current stage. For example, if...
Travis Illig
1

votes
0

answer
208

Views

Can I use a Spring @Value variable from properties in another annotation?

I currently have a variable coming from a property file, declared as: @Value('${retryLimit}') private int retryLimit; That I would like to use in an annotation instead of the hard-coded constant '3' in this case: @Retryable(maxAttempts = 3, backoff = @Backoff(delay = 2000)) Is this possible? I've t...
user2440671
1

votes
1

answer
22

Views

How to detect if SpelExpressionParser did not find a variable in a context

I have a simple Question, but I don't found anything in the web. Here is an example: SpelExpressionParser parser = new SpelExpressionParser(); StandardEvaluationContext ctx = new StandardEvaluationContext(); ctx.setVariable('variable', 'value'); Expression expression = parser.parseExpression('variab...
Jevgenij Huebert
1

votes
0

answer
41

Views

How can I get a Path object from a String property using SpEL

I have a String property set in my application.properties set like this: something.some-path='something/somewhere' And I want to convert it into a Path object using SpEL. I tried doing it this way, but it doesn't work: class SomeClass { @Value('#{T(java.nio.file.Paths).get('${something.some-path}')}...
D.Tomov
1

votes
0

answer
13

Views

Spring Expression Language nested projections

Is there any way (or a workaround) to perform nested projection in expressions with access to parent projection context? What I want to evaulate is collection.![#this.someList.?[#this.id == #parent.id]] where #parent presumably refers to #this of collection.! projection.
bottaio
1

votes
2

answer
34

Views

How to detect if user input have one word only in Watson Assistant?

I am using the IBM Watson Conversation Assistant Chatbot. I am having troubles finding in the documentation how to detect if the user input consists of a single word. It's fine for simplicity and for my goal to use the presence of spaces as surrogate (no spaces means only word). I tried using SpEL....
Daniele D.
1

votes
1

answer
887

Views

Spring Ehcache : Delete entries by a condition like endDate > now

I would like to delete entries that satisfy a condition(e.g : Delete entries endDate > now) using annotation provided by Spring over Ehcache, maybe with a SpEl expression. Something like that : @CacheEvict(value = Array('intensities'), condition = 'samples.end > now') def save(samples: Samples[Int...
Nicolas Henin
1

votes
1

answer
683

Views

Is it possible to use Spring SpEL expression in c:set to instantiate new class?

I would like to do something like: but this doesn't work. Is there something like this possible?
Marcel Overdijk
1

votes
1

answer
729

Views

Spring expression 'literal' in XML config file

I have a simple class something like: public class ValueProvider { public void setExpression(String expression) { this.expression = expression; } public String getValue() { Expression exp = new SpelExpressionParser().parseExpression(this.expression); return exp.getValue(new StandardEvaluationContex...
Pete
1

votes
1

answer
176

Views

How to authenticate against a collection of domain objects in Spring Expression Language SpEL

My principle is an instance of 'foo' that has a collection of 'bars'. Each 'bar' has an id that I want to match with the 'id' passed as the resource requested. Can I do something like the following in Spring SpEL? And if so, how? Example (psuedo syntax; cause I don't know the correct way which is...
Christian Bongiorno
1

votes
2

answer
573

Views

Spring @Cachable bean reference in key

I want to use the @Cachable annotation on one of my methods, but I have the problem, that the result depends on an attribute of a spring bean that is not part of the method signature. So I want something like this: @Cachable(value='mycache', key='#id, #myspringbean.referenceId') MyResult myMethod(in...
Tim
1

votes
1

answer
927

Views

Check an environment variable for null and get a file in SpEL

In our prod environment, we supply confDir parameter from server.xml in tomcat to get .properties file, but in dev and test environments we use the properties file in classpath. Like this Now I want to load these properties files using util:properties tag, like shown below, for accessing them in @Va...
harrsha
1

votes
2

answer
1.5k

Views

Spring @Value with multimine properties file value

Spring (3.1): Given a property file with multi line value (of course the real value is much larger): requestStatuses=select sysdate \ from dual I have set up Spring as described: And used as described: @Value('#{sql_lookup_data_repo.requestStatuses}') public void setRequestStatuses(String requestSt...
takacsot
1

votes
1

answer
176

Views

+/- operators for dates in SpEL

According to the documentation, + and - operators can be used on dates in SpEL. However, I couldn't find neither the meaning/signature of these ops nor an example. Does anyone know how this works?
user998692
1

votes
3

answer
669

Views

How to evaluate a dynamic/nested Spring property placeholder expression?

I'm working on a JSP tag. Here is the old line that starts looping through items in a model: But the code has been refactored so the model path (model.sharingTocs above) is now dynamic rather than fixed. It is now passed into the tag via a JSP @attribute: So ${path} now evaluates to 'model.sharingTo...
Steve Chambers
1

votes
1

answer
563

Views

how to remove class cast exception in spring java?

I have written code that uses spring util namespace. I have a class named City with the following properties: private List name; private List state; private List population; //setter and getter methods go here ... and I configured the application context as: p:name='chennai' p:state='tamilnadu' p:po...
Sujith Kumar A
1

votes
1

answer
793

Views

Java Expression Language Projection for each element in collection get new Object of other type

I have below given scenario and problem , looking for someone to provide solution/suggestion. Scenario: There are different types of business-beans objects, these business-beans do not having common properties and cannot be generalized. For different task/job I have to deal with collection of busi...
Deep Saurabh
1

votes
1

answer
1.7k

Views

Spring SpEL and BigDecimal expressions

We're using Spring Expression Language (v3.1.2) to validate Object values in a map. The two test cases below outline a scenario where we are asserting the value of a BigDecimal object. The first case passes but the second test fails. I think the way we have defined the expression is correction, but...
emeraldjava
1

votes
1

answer
511

Views

SpEL expressions - identify fields declared in an expression?

I have the following code which evaluates a SpEL expression using data values defined in a Map object. // data map Map dataMap = new HashMap(); dataMap.put('abc',1); dataMap.put('def',2); dataMap.put('xyz',1); dataMap.put('qwerty',2); // spel rule expression String ruleExpression = '#abc+#def'; //...
emeraldjava
1

votes
1

answer
323

Views

Add setShouldAppendNewLine to FileWritingMessageHandler in Spring Integration

I'm using Spring Integration 4.1.0. I have a use case where I'd like to produce a single file that will contain a row for each message that flowed to a channel. Shown below is the config to do that, as per the 'Define an integration flow' section of this link: https://spring.io/guides/gs/integratio...
Tony Falabella
1

votes
1

answer
480

Views

Configure Spring Integration SpEl in java config

I'm using spring integration to call another service via http. I'm using annotations for configuring spring integration, but I have a problem when I want my service url be configurable based on message payload. Current code looks like this: @Bean @ServiceActivator(inputChannel = 'myChannel') public...
Meysam
1

votes
1

answer
1.7k

Views

SpelEvaluationException interpreting “access” string in ResourceServerConfigurerAdapter

Any ideas on this? From Tomcat: Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1011E:(pos 8): Method call: Attempted to call method throwOnError(java.lang.Boolean) on null context object Returned to Client: java.lang.IllegalArgumentException: Failed to evaluate express...
JvmSd121
1

votes
1

answer
625

Views

Several beans implementating the same interface

The exact usage is like this: @Slf4j public class Client { @Getter @NonNull private final UpdateListener updateListener; @NonNull private final SubscriptionFactory subscriptionFactory; @NonNull private final Map updatedRegistry = new ConcurrentHashMap(); public Client(UpdateListener updateListener,...
Eddie Jamsession
1

votes
1

answer
228

Views

Spring Data JPA with Security EvaluationContextExtensionSupport not working

I wanted to use Spring Data JPA's Security Extension support to perform a check on user's authority and accordingly fetch some values. I'm trying to do this as indicated here Below is my code snippet @RepositoryRestResource(collectionResourceRel = 'ProductStatus', path = 'ProductStatus') public inte...
rakpan
1

votes
1

answer
5.1k

Views

Cron expression must consist of 6 fields (found 1 in “#{systemEnvironment['db_cron']}”)

I'm trying to set a cron Scheduled annotation as follows: @Scheduled(cron = '#{systemEnvironment['db_cron']}') def void schedule() { } Next set the environment variable as: export db_cron='0 19 21 * * *' However, I get the runtime error: Cron expression must consist of 6 fields (found 1 in '#{syste...
Chris Snow
1

votes
1

answer
261

Views

injection of empty set from reading properties

I am setting a list of Ids with spring bean and I was wondering if there was a way of initialising my collection Set to be empty with SPEL if no properties were set: list.ids= such that when I call... if (connection.getListOfIds().isEmpty()) { //do something } it returns that the set contains no e...
M06H
1

votes
2

answer
525

Views

Templating using Spring El expression

I would like using spring el for simple templating like 'Some text: #{some dynamic value from map}'. In my case, examples from docs doesn't fit, because it work only for value form map: Map data = new HashMap(); data.put('property', 123); String message = '#data['property']'; ExpressionParser parser...
qwe asd
1

votes
2

answer
105

Views

How to pass JobParams to other beans in xml?

There are two job params filePath & fileName for my spring batch job. Requirement is to pass this filePath+fileName to other custom bean as a property value. However, I cannot 'step' scope that bean to access these params. Hence I need a way to access these job params from (non-step) normal bean. Pl...
skpraveen
1

votes
2

answer
1.1k

Views

Spring SpEL - set a property only if the value is not null

I'm using Spring and I want to set a property only if the value passed is not null? I tried this example but it doesn't work. I want to add the property only if it is not null else not add it. I don't want to add a default value. Thanks for your help #{mailProperties['mail.smtp.starttls.enable']:''...
Imar
1

votes
1

answer
700

Views

Spring EL - “There is still more data in the expression”

Is it possible to parse an expression like the one shown below, where I call a method and would like to have text after the result of that method call? String expression = 'obj.someMethod()'test''; ExpressionParser parser = new SpelExpressionParser(); Expression expression = parser.parseExpression(...
Steve

View additional questions