我有一个 Spring Boot 应用程序,我想将其部署在 Spring Cloud Dataflow 服务器上。我面临应用程序属性的问题。由于某种原因,嵌套属性 不显示在数据流 UI 中。为什么会发生这种情况?
我已在 application.yml 文件中定义了我的属性。 我已在 dataflow-configuration-metadata.properties 中声明了我的属性 我正在将 Spring Boot jar 文件从 maven 源注册到 SDF 中,然后将其添加到任务中。在任务中,“选项”按钮不会获取我的所有属性。
我的应用程序包括 Spring Batch、Spring Web、Hibernate、JaxB、mapstruct 和 lombok。
最佳答案
首先,由于您提到您正在使用 Lombok,因此您需要确保 pom.xml
中的依赖项已正确配置。
根据 Spring 的文档 ( Configuration Metadata )
If you are using Lombok in your project, you need to make sure that its annotation processor runs before spring-boot-configuration-processor. To do so with Maven, you can list the annotation processors in the right order using the annotationProcessors attribute of the Maven compiler plugin. If you are not using this attribute, and annotation processors are picked up by the dependencies available on the classpath, make sure that the lombok dependency is defined before the spring-boot-configuration-processor dependency.
基于此,如果您使用 maven-compiler-plugin
,则必须按以下顺序声明注释处理器:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler-plugin.version}</version>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.mapstruct-processor.version}</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${org.projectlombok.lombok.version}</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-mapstruct-binding</artifactId>
<version>${org.projectlombok.ombok-mapstruct-binding.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
转到属性,我们假设 application.yml
如下所示:
my-app:
name: AppName
config:
port: 8080
那么配置属性类应该是:
@Data
@Configuration
@ConfigurationProperties(prefix = "my-app")
public class AppProperties {
/**
* Name
*/
private String name;
private final Config config = new Config();
@Data
public static class Config {
/**
* Port
*/
private int port;
}
}
为了让 Dataflow UI 正确显示属性,META-INF/dataflow-configuration-metadata.properties
将为:
configuration-properties.classes=com.example.app.AppProperties,\
com.example.app.AppProperties$Config
重要提示:请注意我们如何在 .properties
文件中声明内部类。
关于spring-boot - Spring Data Flow Task 不显示 Spring Boot 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75664205/