Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After native-image packaging, the @Resource annotation cannot be dependency injected #38742

Closed
funky-eyes opened this issue Dec 12, 2023 · 2 comments
Labels
for: external-project For an external project and not something we can fix status: duplicate A duplicate of another issue

Comments

@funky-eyes
Copy link

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 [email protected]/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

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 12, 2023
@funky-eyes
Copy link
Author

funky-eyes commented Dec 12, 2023

The @Autowired annotation is also fine, it works perfectly.

@wilkinsona
Copy link
Member

Duplicates spring-projects/spring-framework#29614.

@wilkinsona wilkinsona closed this as not planned Won't fix, can't repro, duplicate, stale Dec 12, 2023
@wilkinsona wilkinsona added status: duplicate A duplicate of another issue for: external-project For an external project and not something we can fix and removed status: waiting-for-triage An issue we've not yet triaged labels Dec 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: external-project For an external project and not something we can fix status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

3 participants