Make spring-task-launch-request-function as auto-config

* Also make a `spring-spel-function`, `spring-filter-function` as auto-config
* Fix Checkstyle violations in those module, as well as in the `spring-payload-converter-function`
This commit is contained in:
Artem Bilan
2024-01-10 09:54:03 -05:00
parent 0f9065df78
commit 97c3be83af
17 changed files with 86 additions and 73 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2020-2020 the original author or authors.
* Copyright 2020-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,14 +18,18 @@ package org.springframework.cloud.fn.spel;
import java.util.function.Function;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.integration.transformer.ExpressionEvaluatingTransformer;
import org.springframework.messaging.Message;
@Configuration
/**
* Auto-configuration for SpEL function.
*
* @author Soby Chacko
*/
@AutoConfiguration
@EnableConfigurationProperties(SpelFunctionProperties.class)
public class SpelFunctionConfiguration {
@@ -33,15 +37,14 @@ public class SpelFunctionConfiguration {
public Function<Message<?>, Message<?>> spelFunction(
ExpressionEvaluatingTransformer expressionEvaluatingTransformer) {
return message -> expressionEvaluatingTransformer.transform(message);
return expressionEvaluatingTransformer::transform;
}
@Bean
public ExpressionEvaluatingTransformer expressionEvaluatingTransformer(
SpelFunctionProperties spelFunctionProperties) {
return new ExpressionEvaluatingTransformer(
new SpelExpressionParser().parseExpression(spelFunctionProperties.getExpression()));
return new ExpressionEvaluatingTransformer(spelFunctionProperties.getExpression());
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2020-2020 the original author or authors.
* Copyright 2020-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,7 +18,8 @@ package org.springframework.cloud.fn.spel;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.expression.Expression;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.integration.expression.FunctionExpression;
import org.springframework.messaging.Message;
/**
* Configuration properties for the SpEL function.
@@ -29,18 +30,18 @@ import org.springframework.expression.spel.standard.SpelExpressionParser;
@ConfigurationProperties("spel.function")
public class SpelFunctionProperties {
private static final Expression DEFAULT_EXPRESSION = new SpelExpressionParser().parseExpression("payload");
private static final Expression DEFAULT_EXPRESSION = new FunctionExpression<Message<?>>(Message::getPayload);
/**
* A SpEL expression to apply.
*/
private String expression = DEFAULT_EXPRESSION.getExpressionString();
private Expression expression = DEFAULT_EXPRESSION;
public String getExpression() {
public Expression getExpression() {
return this.expression;
}
public void setExpression(String expression) {
public void setExpression(Expression expression) {
this.expression = expression;
}

View File

@@ -0,0 +1,4 @@
/**
* The SpEL function auto-configuration support.
*/
package org.springframework.cloud.fn.spel;