spring-el

Spring Expression Language (SpEL) is not working when hyphen is used

僤鯓⒐⒋嵵緔 提交于 2020-07-16 10:07:00
问题 I am trying to parse an expression by using Spring Expression Language. if myVariable value is set to "first-name" (value with hyphen) then getting class.org.springframework.expression.spel.SpelParseException . ExpressionParser parser = new SpelExpressionParser(); String parsedDynamicVariablesValue = parser.parseExpression("#" + myVariable).getValue(stdContext, String.class); how to solve issue with the hyphen? Reference Used: Spring Expression Language (SpEL) 回答1: It doesn't work that way,

Spring @Value with arraylist split and obtain the first value

北城以北 提交于 2020-06-17 15:48:31
问题 Spring @Value with arraylist split and get the first value of arrayList I had my.list=a,b,c I am struggling to get the first value i.e., a I tried, @Value("#{'${my.list}'.split(',')}) List<String> values; String myVal = values.get(0); Is there any better method than this procedure? 回答1: U have a syntax error in this line @Value("#{'${my.list}'.split(',')}) That should be corrected as below @Value("#{'${my.list}'.split(',')}") List<String> values; I would suggest you below solution as a better

SpEL @ConditionalOnProperty string property empty or nulll

☆樱花仙子☆ 提交于 2020-05-15 05:34:47
问题 I am currently having trouble with my dataSource bean creation on condition of String property from my applications.yaml file. Ideally, I would only like to create the dataSource bean only if the url is set in my application.yaml file. Shouldn't create the bean if its not present (empty or null). I know this condition checks on boolean but is there anyway to check if the string property is empty or null? DatabaseConfig.java @Configuration public class DatabaseConfig { @Value("${database.url:}

SpelParseException: After parsing a valid expression, there is still more data in the expression: 'lcurly({)'

心已入冬 提交于 2020-05-14 18:52:45
问题 I am trying to condtionally create a component using @ConditionalOnExpression("not ${service.synchronous} && not ${service.disabled}") . I based this on Spring Boot SpEL ConditionalOnExpression check multiple properties, which provides a multi-property conditional as follows: @ConditionalOnExpression("${properties.first.property.enable:true} && ${properties.second.property.startServer:false}") However, I keep getting: Caused by: org.springframework.expression.spel.SpelParseException: EL1041E:

how to use Spring-EL in @Value when using constants to resolve a property

对着背影说爱祢 提交于 2020-05-14 18:39:49
问题 I'm trying to use a constant to define a property and then resolving it with the @Value annotation. I defined the constant in an interface: public interface InternalConstant{ public static final String JOB_NAME_PROPERTY = "javabatch.jobName"; } I'm using springboot and I'm adding the property as a default property to the context: SpringApplication springApp = new SpringApplication(configs.toArray()); Properties props = new Properties(); props.setProperty(InternalConstants.JOB_NAME_PROPERTY,

Caused by: org.springframework.expression.spel.SpelParseException: Expression [] @31: EL1043E: Unexpected token. Expected 'colon(:)' but was 'rcurly(}

大城市里の小女人 提交于 2020-04-11 06:41:19
问题 I went through links like: How to pass a Map<String, String> with application.properties before posting the questions, but this doesn't fulfill my requirements. application.properties soap.all.endpoints={getEmployeeRoles: ['ABC', 'EFG'], getStudentRoles: ['PQR', 'XYZ']} I am reading using below code, but it gives me error. @Value("#{${soap.all.endpoints}}") private Map<String, List<String>> roles; Error : Caused by: org.springframework.beans.factory.BeanExpressionException: Expression parsing

Spring SpEL - Expression Language to create Map of String and Custom Object

早过忘川 提交于 2020-04-07 01:07:56
问题 I'm using Spring Boot example to read the following from the properties file. sub.region.data={\ AF: {'subRegionCd' : '34', 'subRegionName' : 'Southern Asia', 'subRegionDesc': '', 'status' : 'A'} \ } I used below, but it doesn't works @Value("#{${sub.region.data}}") private Map<String, SubRegion> subRegionsMap; SubRegion.java public class SubRegion { private String subRegionCd; private String subRegionName; private String subRegionDesc; private String subRegionStatus; } I am getting below

Spring SpEL - Expression Language to create Map of String and Custom Object

喜欢而已 提交于 2020-04-07 01:06:35
问题 I'm using Spring Boot example to read the following from the properties file. sub.region.data={\ AF: {'subRegionCd' : '34', 'subRegionName' : 'Southern Asia', 'subRegionDesc': '', 'status' : 'A'} \ } I used below, but it doesn't works @Value("#{${sub.region.data}}") private Map<String, SubRegion> subRegionsMap; SubRegion.java public class SubRegion { private String subRegionCd; private String subRegionName; private String subRegionDesc; private String subRegionStatus; } I am getting below

Why SpEL support doesn't work in Spring Data JPA @Query?

主宰稳场 提交于 2020-02-24 12:18:10
问题 I'm trying to avoid redundancy with passing second argument to method with list size. Instead, I use EL, but I have an error: org.hibernate.QueryException: Not all named parameters have been set: [ $synthetic$__1] [SELECT distinct b FROM Book b join b.bookHashtags as ht where ht.hashtagName in :tags group by b.uniqueIdentifier having count(ht.uniqueIdentifier) = : $synthetic$__1] @Repository public interface BookRepository extends JpaRepository<Book, Long>, JpaSpecificationExecutor<Book> {

Why SpEL support doesn't work in Spring Data JPA @Query?

对着背影说爱祢 提交于 2020-02-24 12:18:10
问题 I'm trying to avoid redundancy with passing second argument to method with list size. Instead, I use EL, but I have an error: org.hibernate.QueryException: Not all named parameters have been set: [ $synthetic$__1] [SELECT distinct b FROM Book b join b.bookHashtags as ht where ht.hashtagName in :tags group by b.uniqueIdentifier having count(ht.uniqueIdentifier) = : $synthetic$__1] @Repository public interface BookRepository extends JpaRepository<Book, Long>, JpaSpecificationExecutor<Book> {