What causes the warning: annotation is not supported in static fields

As I know, using @Autowiredannotation for fields staticusing is Springnot possible. When I start my server JBosseverything works fine, but I see a few warnings:

Autowired annotation is not supported on static fields: private static ...

I do not use this annotation very often (I have not used it in this project yet), but perhaps some of my colleagues find it more useful.

So, I accepted one of these warnings:

Autowired annotation is not supported on static fields: private static java.lang.String com.my.package.MyClass.myVariable

I opened this class, and inside:

@Value("${params.myvariable}")
private static String myVariable;
    // getter
    // setter

I discovered config.xml:

<bean id="myid" class="com.my.package.MyClass">
    <property name="myVariable" value="${params.myvariable}" />
</bean>

As a last resort, I searched for strings Eclipsefrom Autowiredin my project. The size of the result set was 0 .

So my question is what causes the warning:

Autowired annotation is not supported on static fields

in this case?

Thank you in advance

+4
1

<bean id="myid" class="com.my.package.MyClass">
    <property name="myVariable" value="${params.myvariable}" />
</bean>

, MyClass,

class MyClass {
    ...
    public void setMyVariable(String value) {
        ...
    }
}

, , ... static

private static String myVariable;
// in setter method
myVariable = value;

static, . Spring beans (), .

+6

Source: https://habr.com/ru/post/1536116/


All Articles