spring-bootspring-data-flow

Spring Data Flow Task does not display Spring Boot properties


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.


Solution

  • 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.