spring-el

how to merge properties from one Java object to another in Java using Spring [SpEL]?

拈花ヽ惹草 提交于 2019-12-11 05:54:09
问题 I'm using Spring but not that familiar with all its capabilities. Looking for a good way to copy fields from one Java object instance to another. I've seen How to copy properties from one Java bean to another? but what i'm looking for is more specific, so here are the details: Suppose I have two instances of some class P, source & target, which have getters and setters a,b,c,d and 20 others. I want to copy the properties of of source into target, but only for all properties in a list of

propertyPlaceHolderConfigurer and environment variable

末鹿安然 提交于 2019-12-11 05:25:35
问题 I am trying to load a property file from an environment variable, so here's what I tried: <bean id="propertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:messages/application.properties</value> <value>file:${My_ENV_VAR}/*.properties</value> </list> </property> <property name="ignoreResourceNotFound" value="true" /> <property name="searchSystemEnvironment" value="true" /> <property name

How to evaluate a dynamic/nested Spring property placeholder expression?

最后都变了- 提交于 2019-12-11 04:29:59
问题 I'm working on a JSP tag. Here is the old line that starts looping through items in a model: <c:forEach var="toc" items="${requestScope[formKey].model.sharingTocs}"> But the code has been refactored so the model path ( model.sharingTocs above) is now dynamic rather than fixed. It is now passed into the tag via a JSP @attribute : <%@attribute name="path" required="true"%> So ${path} now evaluates to "model.sharingTocs" . How can items now be assigned? 回答1: Well. Good question. This is a

Cron expression must consist of 6 fields (found 1 in “#{systemEnvironment['db_cron']}”)

时间秒杀一切 提交于 2019-12-11 03:42:46
问题 I'm trying to set a cron Scheduled annotation as follows: @Scheduled(cron = "#{systemEnvironment['db_cron']}") def void schedule() { } Next set the environment variable as: export db_cron="0 19 21 * * *" However, I get the runtime error: Cron expression must consist of 6 fields (found 1 in "#{systemEnvironment['db_cron']}") What can be going wrong? EDIT I have also tried: @Scheduled(cron = "${db_cron}") But this returns a compile time error: /Users/snowch/repos/sales/Prospects/Snow/Plugwise

Access application properties within SpEL in Spring xml configuration

走远了吗. 提交于 2019-12-11 01:38:28
问题 I'm trying to configure a spring bean based on an application property, my end goal is described in the following pseudo code: if ${my.config} <bean id="myBean" class="path.to.MyBeanImplOne" /> else <bean id="myBean" class="path.to.MyBeanImplTwo" /> end where my.config is a boolean property. According to this SpEL guide, #{${my.config} ? 'path.to.MyBeanImplOne' : 'path.to.MyBeanImplTwo'} is a valid expression, so I tried the following configuration: <bean id="myBean" class="#{${my.config} ?

Referring to ConfigurationProperties Beans in SpEL expression in @Configuration bean

爷,独闯天下 提交于 2019-12-10 16:46:57
问题 I have this properties class: import java.util.List; import org.springframework.boot.context.properties.ConfigurationProperties; @ConfigurationProperties("some") public class SomeProperties { private List<String> stuff; public List<String> getStuff() { return stuff; } public void setStuff(List<String> stuff) { this.stuff = stuff; } } and I enable configuration properties in an @Configuration class like so: import org.springframework.boot.context.properties.EnableConfigurationProperties;

How to implement annotation based security using Spring AOP?

假装没事ソ 提交于 2019-12-10 15:59:20
问题 I'm new to Spring AOP (and AOP in general), need to implement the following: @HasPermission(operation=SecurityOperation.ACTIVITY_EDIT, object="#act") public Activity updateActivity(Activity act) { ... } @HasPermission is my custom annotation, which will be used to mark all methods requiring pre-authorization. I'm using my custom implementation of security checks based on Apache Shiro. Generally, I guess that I will need to define pointcut which matches all annotated methods and also provide

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

狂风中的少年 提交于 2019-12-10 11:28:39
问题 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

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

[亡魂溺海] 提交于 2019-12-10 10:31:59
问题 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

Spring Integration DSL - Outbound Gateway with access to Headers

三世轮回 提交于 2019-12-10 06:25:32
问题 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