spring boot: 3.2.0 code:

jakarta.annotation.Resource
    @Resource
    private ZkHolder zkHolder;
public List<KafkaCluster> findAllCluster() {
    final List<KafkaCluster> lst = Lists.newArrayList();
    try {
        final List<String> names = zkHolder.getClient().getChildren().forPath(CLUSTERROOT);
        if (names != null) {
            for (final String name : names) {
                final KafkaCluster kc = clusters.get(name);
                lst.add(kc);
            }
        }
    } catch (Exception e) {
        log.error("findAllCluster", e);
    }
    return lst;
}


error:

java.lang.NullPointerException: null
        at cn.tongdun.ksyncer.biz.scheduler.SyncChannelManager.findAllCluster(SyncChannelManager.java:131)
        at cn.tongdun.ksyncer.web.IndexApi.queryCluster(IndexApi.java:41)
        at java.base@21.0.1/java.lang.reflect.Method.invoke(Method.java:580)
        at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:254)
        at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:182)

But I don't have this problem as long as I use the constructor for dependency injection, please tell me how I can use these annotations under native-image

Comment From: funky-eyes

The @Autowiredannotation is also fine, it works perfectly.

Comment From: wilkinsona

Duplicates https://github.com/spring-projects/spring-framework/issues/29614.