Why is this an issue?

Spring dependency injection framework does not support injecting data into static fields. When @Value, @Inject, or @Autowired are applied to static fields, they are ignored.

What is the potential impact?

This rule raises an issue when a static field is annotated with @Value, @Inject, or @Autowired.

How to fix it

Either use an instance field instead of a static field or remove the @Value, @Inject, or @Autowired annotation and initialize the field.

Code examples

Noncompliant code example

@Component
public class MyComponent {

    @Value("${my.app.prop}")
    private static SomeDependency dependency; // non compliant, @Value will be ignored and no value will be injected
    // ...
}

Compliant solution

@Component
public class MyComponent {

    @Value("${my.app.prop}")
    private final SomeDependency dependency;
    // ...
}

Resources

Articles & blog posts