spring-el

Extending SpEL with own methods in Grails?

寵の児 提交于 2019-12-05 20:30:26
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 SpringSecurityCoreGrailsPlugin.groovy also gives me no insights. This is only available if you also have the spring

How to get raw value of property containing placeholders?

萝らか妹 提交于 2019-12-05 13:54:11
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 way to do get getPersonExpression() to return the string literal ${person.surname} without attempting to

Spring Integration DSL - Outbound Gateway with access to Headers

早过忘川 提交于 2019-12-05 12:51:48
I'm having an issue with Spring Integration. I'm using Spring Boot 1.4.0.RELEASE, Spring Integration 4.3.1.RELEASE, Spring Integration DSL 1.2.0.M1. What I'm trying to do: I'm writing an application that will read files from FTP and local file system (using inbound channel adapters), transfer the files to a local working directory (using file outbound gateways), process, then move them to a final destination (file outbound gateway/adapters). EDIT: The original issue stemmed from incorrect usage of the OutboundGateway . For details of what I was doing wrong, look at the edit history. I'm having

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

微笑、不失礼 提交于 2019-12-05 12:25:24
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) on null context object you need to add several things in order to get this thing working. You have

Evaluating properties inside Spring Expression Lang (SpEL)

╄→гoц情女王★ 提交于 2019-12-05 09:35:53
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 refreshIntervalMillis to refreshIntervalMinutes Changed to code above to the following: p:repeatInterval="

Injecting property values from property file or xml file into PreAuthorize(…) java annotation (Unresolved)

只谈情不闲聊 提交于 2019-12-05 00:56:57
问题 I've asked this question in my previous post here: SpEL for spring security: Passing Values from XML to Java based SpEL configuration. But it wasn't yet resolved. I want to inject values either from an xml configuration or from external file into @PreAuthorize(...) annotation. It is not easy like injecting by using @Value annotation. To recall the question, I provide the following information. I have the following xml configuration file (example.xml) that has properties and initialized its

Use instanceof in Thymeleaf

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 18:07:39
问题 Is there a way to use the Java instanceof operator in Thymeleaf? Something like: <span th:if="${animal} instanceof my.project.Cat" th:text="A cat"></span> <span th:if="${animal} instanceof my.project.Dog" th:text="A dog"></span> 回答1: Try: <span th:if="${animal.class.name == 'my.project.Cat'}" th:text="A cat"></span> or, if using Spring: <span th:if="${animal instanceof T(my.project.Cat)}" th:text="A cat"></span> more about using SpEL and dialects in thymeleaf. 来源: https://stackoverflow.com

String.replace() returns unwanted string

我们两清 提交于 2019-12-04 14:13:00
I'm working on a piece of code where I've to split a string into individual parts and replace them. The basic logic flow of my code is, there's a string that contains a formula. The numbers below on the LHS, i.e 1, 2 and 3 are ids of different objects. Once I split them, I'd use these ids, get the respective value and replace the ids in the below String with its respective values. The string that I have is as follow - String str = "(1+2+3)>100"; I've used the following code for splitting the string - String[] arraySplit = str.split("\\>|\\<|\\="); String[] finalArray = arraySplit[0].split("\\(

Thymeleaf and #fields.hasErrors

好久不见. 提交于 2019-12-04 11:51:57
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 " and this causes Thymeleaf to fail with this error: HTTP Status 500 - Request processing failed;

How to define default null value in application.yml in Spring Boot

冷暖自知 提交于 2019-12-04 09:35:52
问题 I'm trying to define the default value as null value in application.yml with SpringBoot version 1.3.0.RELEASE. The goal is be able to refer it with a class with ConfigurationProperties annotation -- application.yml -- test.foo: ${test.bar:#{null}} but it doesn't work. If the value of test.bar is not defined, set test.foo to null (default value) I already have spring-el in my dependencies. I don't want to use PropertyPlaceholderConfigurer.setNullValue It's seem to work in @Value but not in