spring-el

SpEL not supported in Spring annotation @Entry.base

安稳与你 提交于 2019-12-23 10:54:46
问题 I use Spring Data LDAP and Spring Boot provides out of the box support for an embedded UnboundID server. However, when I use Spring Data LDAP's @Entry annotation, I need to specify a different base in the annotation based on whether I'm using the embedded UnboundID LDAP server, or a remote Active Directory server. I was attempting to do this with SpEL and profile-based properties by specifying: @Entry(base = "${ldap.person.base}", ...) Then I have an application.propreties with ldap.person

Map for spring expression language

懵懂的女人 提交于 2019-12-23 03:07:25
问题 I want to use SpEL to evaluate some predicates. Since the values/properties are dynamic, I don't have a certain bean class. Therefore, we have a hashmap where (according to the appliction state) the keys map to different POJOs/beans, e.g.: Person person = new Person();// a person instance person.setAge(25) // e.g. property age Map<String, Object> model = new HashMap<>(); model.put("person", person); // and others ... We expected to use the Evaluation Context for this by setting the variables,

Extending SpEL with own methods in Grails?

倖福魔咒の 提交于 2019-12-22 09:27:52
问题 I'd like to add custom SpEL methods in Grails applciation, like it's done for plain Spring-Security application in this question, by overriding EvaluationContext. Will this work? How do I plug global-method-security into security config? I can configure security, but what to add there? Something like grails.plugins.springsecurity = { 'global-method-security' { 'expression-handler' { ref("myMethodSecurityExpressionHandler") } } } ? But what code will interpret it? Looking into

Pass method argument in Aspect of custom annotation

醉酒当歌 提交于 2019-12-21 07:59:06
问题 I'm trying to use something similar to org.springframework.cache.annotation.Cacheable : Custom annotation: @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface CheckEntity { String message() default "Check entity msg"; String key() default ""; } Aspect: @Component @Aspect public class CheckEntityAspect { @Before("execution(* *.*(..)) && @annotation(checkEntity)") public void checkEntity(JoinPoint joinPoint, CheckEntitty checkEntity) { System.out

How do I escape values in SpEL?

会有一股神秘感。 提交于 2019-12-19 14:57:03
问题 I am writing some SpEL statements in XML, and I can't get the parser to determine when I need to escape a character. I've attempted the following: <... property="someProperty" value="#{ someBean.aMethodOnTheBean('st\'ring') }" /> However adding in the \' does not seem to escape that single quote and I keep receiving a parser exception. Is there any way to escape these values? 回答1: From the documentation: "To put a single quote itself in a string use two single quote characters." expression =

Thymeleaf compare #locale expression object with string

霸气de小男生 提交于 2019-12-19 10:37:08
问题 I want to set a th:class attribute depending on the context locale using the expression object #locale. I have tried th:class="${#locale}=='en'?'active':''" th:class="${#locale=='en'}?'active':''" Both of them results in false, but whent I print it with th:text="${#locale}, I got the correct locale code (en,es). Any idea of how to compare the #locale object with a locale code? 回答1: Based on the answer posted by David_Garcia, I could resolve my issue this way: th:class="__${#locale}__=='en'?

Programmatically evaluate a bean expression with Spring Expression Language

对着背影说爱祢 提交于 2019-12-18 15:38:06
问题 I have a simple Spring Bean Expression, which evaluates fine when I define it inside an application context file: <bean id="myConfigBean" class="com.example.myBeanConfigBean"> <property name="myProperty" value="#{ someOtherBean.getData() }"/> </bean> Now, I want to do the same evaluation programmatically. I have used the following code: final ExpressionParser parser = new SpelExpressionParser(); final TemplateParserContext templateContext = new TemplateParserContext(); Expression expression =

spring expression read file content

99封情书 提交于 2019-12-18 12:34:11
问题 How to use spring expression to read file content and put it into a string? I would like to do the following. For example, @Value("classpath:myquery.sql") File f; @Value("#{org.apache.commons.io.FileUtils.readFileToString(f)}") String sql; Or even better @Value("#{FileUtils.readFileToString(classpath:myquery.sql)}") String sql; However, none of above code work. Just to mention I am using spring version 3.2.0 Thanks. 回答1: Finally got the answer myself... @Value("#{T(org.apache.commons.io

How does Spring 3 expression language interact with property placeholders?

血红的双手。 提交于 2019-12-17 10:23:49
问题 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

Using a static variable value in Qualifier annotation

妖精的绣舞 提交于 2019-12-13 06:01:58
问题 Is it possible to pass a static variable defined in a class as argument to @Qualifier annotation? I tried the below format and a few other variations, but nothing worked. @Qualifier("T(com.test.Constants).BEAN_NAME") Spring-el works in @Value annotation. For example, below example is valid: @Value("#{ systemProperties['user.region'] }") 回答1: Try with @Qualifier(com.test.Constants.BEAN_NAME) 来源: https://stackoverflow.com/questions/16472627/using-a-static-variable-value-in-qualifier-annotation