FAQ Database Discussion Community


Thymeleaf compare #locale expression object with string

conditional,locale,thymeleaf,spring-el
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...

spring property resolution from a spring expression

spring,spring-el
I want to resolve a property and specify the name of the property using a Spel expression. If I do this <property name="host" value="#{T(...Constants).SINK_PROP_HOST}" /> the value gets resolved correctly to sink.host which is the value of this constant. Taking it a step further <property name="host" value="${#{T(...Constants).SINK_PROP_HOST}}" /> This doesn't...

@DateTimeFormat annotation not working in Spring Controller

spring-mvc,spring-el
I am following Spring Documentation 4. Through its guidelines I successfully collected the correctly formatted Date field. The Controller Class is @Controller public class HomeController{ @RequestMapping("/home") public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { return new ModelAndView("page1", "myForm", new MyForm()); } } MyForm Class has a field date annotated...

Several beans implementating the same interface

spring,spring-el,spring-rabbit
The exact usage is like this: @Slf4j public class Client<E, Key> { @Getter @NonNull private final UpdateListener<E, Key> updateListener; @NonNull private final SubscriptionFactory subscriptionFactory; @NonNull private final Map<Key, Instant> updatedRegistry = new ConcurrentHashMap<>(); public Client(UpdateListener<E, Key> updateListener, SubscriptionFactory subscriptionFactory) { this.updateListener = updateListener; this.subscriptionFactory = subscriptionFactory;...

@Cacheevict sometimes missing an object in the context (EL1011E)

java,spring,caching,spring-el
Iā€™m fighting with the error about a week without any result. I have a legacy Spring application which was upgraded to Spring 3.2.11.RELEASE and Hibernate 4.2.15.Final. There is a class containing Spring cache annotated methods: public class GroovyFormulaScriptCompilerImpl implements FormulaScriptCompiler, CacheFlusher<ClassifyObjectAttributePlain>, InitializingBean { ā€¦ @Override @Cacheable(value="compile_cache", key="'formulaforAttribute' + #classifyObjectAttribute.getPlainId()") public...

how to use Spring-EL in @Value when using constants to resolve a property

spring,spring-boot,spring-el,spring-environment
I'm trying to use a constant to define a property and then resolving it with the @Value annotation. I defined the constant in an interface: public interface InternalConstant{ public static final String JOB_NAME_PROPERTY = "javabatch.jobName"; } I'm using springboot and I'm adding the property as a default property to the...

Spring xml dynamic property placeholder construction

xml,spring,dynamic,properties,spring-el
I would like to dynamically construct a property value expression, as in <property name="server" value="#{'${host}' + {systemProperties['myEnv']}}" /> Let's say the property host exists in a property file aand it's value is 'myserver.net' and the system property myEnv has been set to 'UAT', then this expression results in a value...

Configure Spring Integration SpEl in java config

java,spring-integration,spring-el
I'm using spring integration to call another service via http. I'm using annotations for configuring spring integration, but I have a problem when I want my service url be configurable based on message payload. Current code looks like this: @Bean @ServiceActivator(inputChannel = "myChannel") public HttpRequestExecutingMessageHandler otherServiceHttpCall() { final HttpRequestExecutingMessageHandler httpHandler...

Cron expression must consist of 6 fields (found 1 in ā€œ#{systemEnvironment['db_cron']}ā€)

spring,groovy,cron,spring-el
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...

How to concatenate a string with SpEL in SpringXD Stream Definition

spring-integration,spring-el,spring-xd
I'm trying to create a stream definition that uses two payload fields joined together to create a concatenated string. stream create --name blah --definition "http | gemfire-json-server --keyExpression=payload.getField('deviceId') + payload.getField('timestamp')" --deploy` The concatenation piece in the keyExpression is incorrect, what should it be to get it to work inline?...

How to assign values for a list of some objects defined as variable with Spring Expression Language(Or the other expression languages you aware of)

java,spring,expression,el,spring-el
In Spel, it is easy to assign some values for a List property. For example having object foo with a property defined as List, I usually do: SpelParserConfiguration config = new SpelParserConfiguration(true,true); ExpressionParser parser = new SpelExpressionParser(config); Foo foo = new Foo(); EvaluationContext context = new StandardEvaluationContext(foo); parser.parseExpression("barList[1].test='11111111'") .getValue(context); But...

How to fill HashMap from java property file with Spring @Value

java,spring,properties-file,spring-el
Is it possible to use Spring @Value, to map values from properties file to the HashMap. Currently I have something like this, and mapping one value is not a problem. But I need to map custom values in HashMap expirations. Is something like this possible? @Service @PropertySource(value = "classpath:my_service.properties") public...