Skip to the content.

Spring Boot Static Property Injector

If you find this project useful, please ⭐ Star ⭐ it and share it with others! This is the best way to show appreciation for this project - Thank you! ❤️

Purpose

Load Spring Boot properties (as SpEL and/or Spring Property Placeholders e.g. @Value-annotation) to static fields!

JavaDoc

The official JavaDoc hosted on javadoc.io.

Example

The following is a simple example of how this library can be used.

1. Import Dependency

<dependency>
    <groupId>io.github.chrimle</groupId>
    <artifactId>spring-boot-static-property-injector</artifactId>
    <version>0.1.0</version>
</dependency>

[!NOTE] This artifact is hosted on

2. Include StaticValueInjector Bean

import io.github.chrimle.sbspi.StaticValueInjector;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication(scanBasePackageClasses = StaticValueInjector.class)
class ExampleSpringBootApplication {}

3. Configure Bean Class Scanning using sbspi.basePackage

sbspi.basePackage=your.example.app.subpackage

4. Annotate Fields with @StaticValue

import io.github.chrimle.sbspi.StaticValue;

public class Example {

  // This field MAY remain null if the property is not set.
  @StaticValue("${myapp.custom.example-nullable-field}")
  private static String EXAMPLE_NULLABLE_FIELD;
  
  // This field MAY be set to "someDefaultValue" if the property is not set.
  @StaticValue("${myapp.custom.example-default-field:someDefaultValue}")
  private static String EXAMPLE_DEFAULT_FIELD;

}

5. If You encounter any issues

  1. For unexpected issues, a StaticValueInjectorException will be thrown with a description of what went wrong.
  2. In case of fields not being set as expected, review the sbspi.basePackage-property and the package name of the relevant class.
  3. Enable DEBUG logs for io.github.chrimle.sbspi to see which fields have been processed.
  4. Open a GitHub issue describing the issue and include the findings from these steps.

Road Map

Plan for the 1.0.0 release.

MAJOR

MINOR

PATCH

Change Log

0.1.0