Spring Value Annotation Processor

Annotation processor to extract all configuration properties injected through Spring @Value annotations

License

License

GroupId

GroupId

com.github.egoettelmann
ArtifactId

ArtifactId

spring-value-annotation-processor
Last Version

Last Version

0.0.2
Release Date

Release Date

Type

Type

jar
Description

Description

Spring Value Annotation Processor
Annotation processor to extract all configuration properties injected through Spring @Value annotations
Project URL

Project URL

https://github.com/egoettelmann/spring-value-annotation-processor
Source Code Management

Source Code Management

https://github.com/egoettelmann/spring-value-annotation-processor

Download spring-value-annotation-processor

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.egoettelmann/spring-value-annotation-processor/ -->
<dependency>
    <groupId>com.github.egoettelmann</groupId>
    <artifactId>spring-value-annotation-processor</artifactId>
    <version>0.0.2</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.egoettelmann/spring-value-annotation-processor/
implementation 'com.github.egoettelmann:spring-value-annotation-processor:0.0.2'
// https://jarcasting.com/artifacts/com.github.egoettelmann/spring-value-annotation-processor/
implementation ("com.github.egoettelmann:spring-value-annotation-processor:0.0.2")
'com.github.egoettelmann:spring-value-annotation-processor:jar:0.0.2'
<dependency org="com.github.egoettelmann" name="spring-value-annotation-processor" rev="0.0.2">
  <artifact name="spring-value-annotation-processor" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.egoettelmann', module='spring-value-annotation-processor', version='0.0.2')
)
libraryDependencies += "com.github.egoettelmann" % "spring-value-annotation-processor" % "0.0.2"
[com.github.egoettelmann/spring-value-annotation-processor "0.0.2"]

Dependencies

test (1)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter jar 5.7.1

Project Modules

There are no modules declared in this project.

Spring Value Annotation Processor

Maven Central CircleCI build (develop)

An annotation processor to extract all configuration properties injected through Spring @Value annotations.

It generates a spring-configuration-metadata.json conforming to the Configuration Metadata format defined by Spring Boot.

Goal of this project

Background

Most of the time, possible configuration properties for legacy Spring projects are maintained manually. Documentation is difficult to keep up to date and becomes easily outdated.

This annotation processor allows to automatically extract all configuration properties at build time. The generated file(s) can be used to:

  • add auto-completion of configuration files in your IDE
  • expose possible configuration properties through your app like Spring Boot Actuator does
  • analyze the project's dependencies on configuration properties
  • generate documentation

Generated metadata

For every class attribute annotated with @Value, the processor will generate:

  • the name of the configuration property used
  • the type of the attribute
  • the description taken from the JavaDoc defined on the attribute (if any)
  • the sourceType of the enclosing class
  • the defaultValue specified in the annotation (if any)

Additionally, the processor recognizes SPEL expressions and extracts properties out of them. In this case the type will not correspond to the property itself, but to the attribute's one. Currently, if multiple properties are used within the same expression, only the first one is extracted.

Usage

If using Maven, you can simply add the project as a provided dependency.

<dependency>
    <groupId>com.github.egoettelmann</groupId>
    <artifactId>spring-value-annotation-processor</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <scope>provided</scope>
</dependency>

If you are using the maven-compiler-plugin for your build, you will have to declare it in the annotationProcessorPaths. The plugin's configuration should look to something like the following:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.1</version>
    <configuration>
        <annotationProcessorPaths>
            <!-- in addition to any other annotation processor (like Lombok, etc.) -->
            <annotationProcessorPath>
                <groupId>com.github.egoettelmann</groupId>
                <artifactId>spring-value-annotation-processor</artifactId>
                <version>0.0.1-SNAPSHOT</version>
            </annotationProcessorPath>
        </annotationProcessorPaths>
    </configuration>
</plugin>

After executing mvn clean package, you can find the spring-configuration-metadata.json file under target/classes/META-INF/.

Versions

Version
0.0.2
0.0.1