spring-attic / spring-native

Spring Native is now superseded by Spring Boot 3 official native support
https://docs.spring.io/spring-boot/docs/current/reference/html/native-image.html
Apache License 2.0
2.74k stars 355 forks source link

@Bean missing in native image #1683

Closed sendev1 closed 2 years ago

sendev1 commented 2 years ago

We have a bean in our spring @Configuration class

 @Bean("ibtAgentPublishingServiceClient")
    public AgentPublishingService getIBTAgentPublishingClient(IBTAgentServiceConfig ibtAgentServiceConfig,
                                                              HostCredentialsHandler hostCredentialsHandler,
                                                              @Qualifier("keystoreConfig") KeystoreConfig keystoreConfig) {
        final SoapServiceConfig agentPublishingService = new SoapServiceConfigImpl(ibtAgentServiceConfig.getAgentPublishingServiceUrl(), 100L, 1);
        final JaxWsProxyFactoryBean factory = getJaxWsProxyFactoryBean(AgentPublishingService.class, agentPublishingService, null);
        IdentityTokenInterceptorUtils.attachAddTokenInterceptor(hostCredentialsHandler, factory, keystoreConfig);
        return (AgentPublishingService) factory.create();
    }

and I see that reflect-config.json has this entry

{
  "name":"com.xxx.ws.xxx.publish.AgentPublishingService"
}

Native image got generated successfully but while running it getting below error. Any help would be appreciated

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.pearsonvue.ws.ibtagent.publish.AgentPublishingService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Qualifier(value="ibtAgentPublishingServiceClient")}
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1799) ~[LocalAthenaBrowserService:5.3.20]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1394) ~[LocalAthenaBrowserService:5.3.20]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1309) ~[LocalAthenaBrowserService:5.3.20]
        at org.springframework.aot.beans.factory.InjectedConstructionResolver.lambda$resolve$0(InjectedConstructionResolver.java:83) ~[na:na]
        at org.springframework.aot.beans.factory.InjectedConstructionResolver.resolveDependency(InjectedConstructionResolver.java:97) ~[na:na]
        at org.springframework.aot.beans.factory.InjectedConstructionResolver.resolve(InjectedConstructionResolver.java:83) ~[na:na]
        ... 44 common frames omitted
wenqiglantz commented 1 year ago

Hi @sendev1, could you let me know if you resolved the issue you raised? If so, how did you fix it? I am running into a similar issue in my Spring Native app.