spring-el

Get Spring profile name with spring EL

 ̄綄美尐妖づ 提交于 2019-12-07 16:34:42
问题 Consider a web based application with spring 4. The spring bean profiles is defined in web.xml like: <context-param> <param-name>spring.profiles.active</param-name> <param-value>prod,edb,cas</param-value> </context-param> Now consider a bean is defined in spring-applicaiton-context.xml as <util:properties id="myPolicy" location= "classpath:/configs/${ACCESS-ACTIVE-PROFILE-SECOND-ITEM}/my-policy.properties" /> Is it possible that I can access the list of active profiles and select the second

How to parse spring security expressions programmatically (e.g. in some controller)

烂漫一生 提交于 2019-12-07 09:16:25
问题 How do you parse spring (web) security expressions like hasRole('admin') programmatically (without using tags, annotations or ... )? (reference doc) I've found Spring: What parser to use to parse security expressions - but I don't know how to find or build the EvaluationContext e.g. inside a spring controller. Without providing an EvaluationContext gives org.springframework.expression.spel.SpelEvaluationException: EL1011E:(pos 0): Method call: Attempted to call method hasRole(java.lang.String

Use complex expression with Spring EL (conditional & parenthesis)

旧街凉风 提交于 2019-12-07 07:57:19
问题 I'm using spring-EL with spring security Is it possible to make 'complex' conditional expressions with parentesis? @PreAuthorize("( hasRole('ROLE_USER') and ( isOwnerDocumentUUID( #docUuids ) ) or hasRole('ROLE_ADMIN') ") throw an java.lang.IllegalArgumentException: Failed to parse expression but @PreAuthorize("hasRole('ROLE_USER') and ( isOwnerDocumentUUID( #docUuids ) ") is accepted. 回答1: You have one extra ( , the following should work: @PreAuthorize("( hasRole('ROLE_USER') and

How to get raw value of property containing placeholders?

血红的双手。 提交于 2019-12-07 07:15:13
问题 I am trying to define the following property in one of my .properties files: personExpression=${person.surname} This is then read by a config class: @Configuration public class TemplateConfig { @Autowired private Environment environment; public String getPersonExpression() { return environment.getProperty("personExpression"); } } However this gives the exception: java.lang.IllegalArgumentException: Could not resolve placeholder 'person.surname' in string value "${person.surname}" Is there a

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

不打扰是莪最后的温柔 提交于 2019-12-07 05:34:25
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 why I am here) @PreAuthorize("principal.transactions.contains(instance where dto.transactionId == instance.id")") public SomeResponse processTransaction(RequestDto dto) { ... } Essentially the equivalent of this for(Transaction t : principal.transactions){ if(t.getId() == dto.getTransactionId())

Evaluating properties inside Spring Expression Lang (SpEL)

柔情痞子 提交于 2019-12-07 03:59:21
问题 Our service has a process that is scheduled according to a properties file, reading the property refreshIntervalMillis . Its value is injected directly in a Quartz trigger with this configuration: <bean name="trigger" class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean " p:repeatInterval="${refreshIntervalMillis}"> ... </bean> However, the admins that install this service think in terms of hours/days, so in order to make thing easier for them, we changed this to: Renamed

How do I reuse a parameter witha Spring-Data-JPA Repository?

半城伤御伤魂 提交于 2019-12-06 07:36:22
In looking at the Query Creation for the Spring Data JPA Repositories, I'm wondering how I would reuse a parameter. For example, how would I name the method if I wanted to do something like: @Query("select c from #{#entityName} c where c.lower <= ?1 and c.upper >= ?1") E findByConversionFor(Double amount); Can that query be converted to a SpEL method name (to be used by the query builder)? It seems like a kludge to require the same value to be passed twice: E findByLowerLessThanOrEqualAndUpperGreaterThanOrEqual(Double a, Double b); // where a==b Just mark your parameter with @Param("amount")

Evaluating ${my.property} as a SpEL expression within a @Value annotation

南楼画角 提交于 2019-12-06 07:14:33
Long story short: Is there a way to interpret the string resulting from ${my.property} as a SpEL expression within a @Value annotation without using converters, e.g. something like @Value("#{${my.property}} )? I have an abstract factory (simplified) that lets me build some common objects that are part of the configuration of my system. @Component public class Factory { public Product makeVal(int x) { return new Product(5); } } In order to be more flexible, I'd like to let users write SpEL expressions in the app.properties file, so that the factory can directly be accessed: my.property =

Thymeleaf and #fields.hasErrors

一曲冷凌霜 提交于 2019-12-06 07:07:18
问题 I have this assignment I am working on for school. Using SpringMVC, Hibernate JPA, and Thymeleaf. The following code below involves a specific attribute called " stringGrade ". I want to validate the input in that field using Hibernate Validator. I cannot seem to get Thymeleaf to read the expression. The arrayList that is looped in the view has a name attribute of " deliverables[0].stringGrade " and so on depending on how many there are. I have tried using " deliverables[ ${stat.index} ].name

Is it possible to read YAML property into Map using Spring and @Value annotation

夙愿已清 提交于 2019-12-06 05:01:43
What I want to be able to do is: YAML: features: feature1: true feature2: false feature3: true Code: @Value("${features}") private Map<String,Boolean> features; I can't figure out what Spring scripting syntax to use to do this (if it's possible at all) Steven I'm using Spring Boot and access custom variables like this: Create a custom class that maps to your custom properties: @Component @ConfigurationProperties(prefix="features") public class ConstantProperties { private String feature1; public String getFeature1(){ return feature1; } public void setFeature1(String feature1) { this.feature1 =