2

I have two projects: A and B. I create a bean in project A like this:

@Configuration
public class ConnectorConfiguration {

    @Bean(name = "CON")
    public ConnectorRegistry connectorRegistry() {
        return new LocalConnectorRegistry();
    }
}

Then in project B I add data to the bean like so:

@Configuration
public class SomeClass {
    @Inject
    private ConnectorRegistry connectorRegistry;

    @Bean
    public Connector SomeClass Connector() {
        Connector connector = new BaseConnector(BLA, contextFactory);
        connectorRegistry.register(connector);
        return connector;
    }
}

and when I get back to project A I have this class:

@Service
@DependsOn("CON")
public class SomeWorker {

    @Autowired
    private ConnectorRegistry connectorRegistry;

but the connectorRegistry here is null, even though I added data to it and I know, by looking a the spring live bean graph the beans are dependence like so: SomeWorker ----> CON <----- SomeClass

So if SomeClass and SomeWorker both looks on the same bean, then it shouldn't be null. what am I missing here?

EDIT: In project A I call to SomeWorker through the SpringBoot main class like this, maybe it relates to the problem:

/**
 * Application entry point
 */
@SpringBootApplication
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
@ComponentScan(value = "com.other.components")
public class MainApp
        extends MainAppSpringBootApplication {

    public MainApp() {
      super(SomeClass.class);
  }

    public static void main(String[] args) {
        ConfigurableApplicationContext ctx = new SpringApplicationBuilder(MainApp.class)
                .initializers(new ZooKeeperPropertiesApplicationContextInitializer())
                .run(args);        
    }
}
9
  • make sure SomeWorker is covered in component scan
    – Arjit
    Commented Jan 2, 2019 at 8:24
  • @Arjit how can I verify it? Commented Jan 2, 2019 at 8:27
  • Can you use @Qualifier("CON") below the autowired bean in SomeWorker class?
    – venkat
    Commented Jan 2, 2019 at 8:28
  • @venkat I can, but in the bean graph I see that they both uses the same bean. Commented Jan 2, 2019 at 8:30
  • @Arjit please see edit Commented Jan 2, 2019 at 8:33

0