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);        
    }
}
Ian Lim
  • 4,164
  • 3
  • 29
  • 43
TheDragoner
  • 273
  • 2
  • 6
  • 17

0 Answers0