英文:
Spring Data Flow Task does not display Spring Boot properties
问题
我有一个Spring Boot应用程序,我想要部署到Spring Cloud Dataflow服务器上。我在应用程序属性方面遇到了问题。出于某种原因,嵌套属性在Dataflow UI中未显示。为什么会发生这种情况?
我已经在application.yml文件中定义了我的属性。
我已经在dataflow-configuration-metadata.properties中声明了我的属性。
我将我的Spring Boot jar文件从maven源注册到SDF,然后将其添加到任务中。在任务内部,"选项"按钮不会获取我的所有属性。
我的应用程序包括Spring Batch、Spring Web、Hibernate、JaxB、mapstruct和lombok。
英文:
I have a Spring Boot application that I want to deploy on a Spring Cloud Dataflow server. I am facing an issue with the application properties. For some reason, nested properties
are not presented in the Dataflow UI. Why is this happening?
I have defined my properties in application.yml file.
I have declared my properties in dataflow-configuration-metadata.properties
I am registering my Spring Boot jar file into SDF from maven source, and then add it to a task. Inside the Task, the Options button does not fetch all of my properties.
My application includes Spring Batch, Spring Web, Hibernate, JaxB, mapstruct and lombok.
答案1
得分: 2
首先,由于你提到你正在使用Lombok,你需要确保你的pom.xml
中的依赖项已经正确配置。
根据Spring的文档 (Configuration Metadata)
> 如果你在项目中使用了Lombok,你需要确保其注解处理器在spring-boot-configuration-processor之前运行。要在Maven中做到这一点,你可以使用Maven编译器插件的annotationProcessors属性按正确顺序列出注解处理器。如果你没有使用这个属性,而是让依赖项中可用的注解处理器自动加载,确保Lombok依赖在spring-boot-configuration-processor依赖之前定义。
基于此,如果你正在使用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 {
/**
* 名称
*/
private String name;
private final Config config = new Config();
@Data
public static class Config {
/**
* 端口
*/
private int port;
}
}
为了使Dataflow UI 正确显示属性,META-INF/dataflow-configuration-metadata.properties
应该包含以下内容:
configuration-properties.classes=com.example.app.AppProperties,\
com.example.app.AppProperties$Config
重要提示: 注意我们如何在.properties
文件中声明了内部类。
英文:
First of all, since you mention that you are using Lombok, you want to make sure that your dependencies in pom.xml
are properly configured.
As per Spring's documentation (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.
Based on that, if you're using the maven-compiler-plugin
, you must declare the annotation processors in the following order:
<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>
Moving on to the properties, let's assume that the application.yml
looks like this:
my-app:
name: AppName
config:
port: 8080
Then the configuration property class should be:
@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;
}
}
In order for Dataflow UI to present the properties correctly, the META-INF/dataflow-configuration-metadata.properties
would be:
configuration-properties.classes=com.example.app.AppProperties,\
com.example.app.AppProperties$Config
Important: Note how we declared the inner class in the .properties
file.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论