spring-el

Calling static methods from Spring Security Expressions?

﹥>﹥吖頭↗ 提交于 2019-12-01 02:05:00
I'm looking for a way to extend Spring Security Expressions to support an existing security infrastructure. I'm aware you can extend the MethodSecurityExpressionRoot as described here , but I also found reference to directly calling static methods through Spring Expression Language (Spring EL or SpEL). Unfortunately the official page on Spring Expression methods doesn't directly describe how to do this. How can I invoke a static method through Spring Expression methods? C. Ross By using the T(fully.qualified.name).methodName() syntax : You can use the special T operator to specify an instance

No bean resolver registered in the context to resolve access to bean

Deadly 提交于 2019-11-30 23:11:50
问题 I'm trying to implement method security using Java Config, but I'm getting a error:- org.springframework.expression.spel.SpelEvaluationException: EL1057E:(pos 1): No bean resolver registered in the context to resolve access to bean 'appPermissionEvaluator' The method is:- @PreAuthorize("@appPermissionEvaluator.hasSystemPermission()") public String something() { ... } The Config class definition is (MethodSecurityConfig.java):- @Configuration @EnableGlobalMethodSecurity(prePostEnabled = true)

How to inject a bean only when it exists

旧巷老猫 提交于 2019-11-30 20:21:15
I have the following structure of spring context files ( -> stands for 'includes') : A1.xml -> B.xml & C.xml A2.xml -> B.xml C.xml defines a bean c B.xml defines a bean b with a dependency on c Obviously this fails for A2, because there is no c defined in the context A2 . How can I specify something like: if you have c in the context inject it in b otherwise just inject null ? I looked into Spring EL but <property name="b" ref="#{ @c?:null}" /> Just gave me a NoSuchBeanDefinitionException for a name which seemed to be the value of b.toString() !? Btw: I already know that this thing is messy as

Spring Expression Language in custom annotation

对着背影说爱祢 提交于 2019-11-30 19:46:32
I want to use Spring Expression Language in a custom Annotation. This annotation will be consumed by a custom Aspect. Check this out: @StatisticEventTrigger(value = TestStatisticEvent.class, expression = "#p1") public void someOtherMethod(String arg1, Long arg2) { As you can see, i want to use the expression (in this case) to retrieve some specific argument. When I have my Aspect, triggering an annotated method, i would like to evaluate the spring expression (programmatically) to retrieve a value to use for further business stuff ;) Any ideas? Google was not my friend so far! I figured it out

What are the Spring Batch “default” Context Variables?

筅森魡賤 提交于 2019-11-30 19:33:12
In the Spring Batch step-scope documentation , there are three unexplained spring-batch context maps: jobParameters , jobExecutionContext , and stepExecutionContext . Springsource sample code, combined: <bean id="flatFileItemReader" scope="step" class="org.springframework.batch.item.file.FlatFileItemReader"> <property name="var1" value="#{jobParameters['input.file.name']}" /> <property name="var2" value="#{jobExecutionContext['input.file.name']}" /> <property name="var3" value="#{stepExecutionContext['input.file.name']}" /> </bean> What are the default parameters available within jobParameters

Using Spring beans as a key with @Cacheable annotation

六月ゝ 毕业季﹏ 提交于 2019-11-30 16:36:37
How to make following to work: - a spring bean that has a method that should be cached with @Cacheable annotation - another spring bean that creates keys for the cache (KeyCreatorBean). So the code looks something like this. @Inject private KeyCreatorBean keyCreatorBean; @Cacheable(value = "cacheName", key = "{@keyCreatorBean.createKey, #p0}") @Override public List<Examples> getExamples(ExampleId exampleId) { ... However the above code doesn't work: it gives following exception: Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1057E:(pos 2): No bean resolver registered

Calling static methods from Spring Security Expressions?

旧城冷巷雨未停 提交于 2019-11-30 16:35:34
问题 I'm looking for a way to extend Spring Security Expressions to support an existing security infrastructure. I'm aware you can extend the MethodSecurityExpressionRoot as described here, but I also found reference to directly calling static methods through Spring Expression Language (Spring EL or SpEL). Unfortunately the official page on Spring Expression methods doesn't directly describe how to do this. How can I invoke a static method through Spring Expression methods? 回答1: By using the T

mongodb multi tenacy spel with @Document

三世轮回 提交于 2019-11-30 15:34:29
This is related to MongoDB and SpEL Expressions in @Document annotations This is the way I am creating my mongo template @Bean public MongoDbFactory mongoDbFactory() throws UnknownHostException { String dbname = getCustid(); return new SimpleMongoDbFactory(new MongoClient("localhost"), "mydb"); } @Bean MongoTemplate mongoTemplate() throws UnknownHostException { MappingMongoConverter converter = new MappingMongoConverter(mongoDbFactory(), new MongoMappingContext()); return new MongoTemplate(mongoDbFactory(), converter); } I have a tenant provider class @Component("tenantProvider") public class

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

北慕城南 提交于 2019-11-30 13:47:20
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 setters } PreAuthorise filter on method . @PreAuthorize("canIEditGroupProfile(#membership.group.id)") public

Spring Expression Language - Java 8 forEach or stream on list

感情迁移 提交于 2019-11-30 09:40:31
Is it possible for stream or forEach on list in SpEL? e.g. List<String> x = new LinkedList<>(Arrays.asList("A","AAB")); ExpressionParser parser = new SpelExpressionParser(); StandardEvaluationContext context = new StandardEvaluationContext(x); parser.parseExpression("x.stream().map(x -> x.replaceAll(\"A\", \"B\")).collect(Collectors.toList())").getValue(context)) SpEL is not Java, it's a different language; the acronym stands for Spring Expression Language . It doesn't understand Java8 lambdas so can't parse x -> ... . Also, static methods are invoked with the T operator. So, this works...