I have this component that looks basically like this: -- Please note, I am trying to have a Spring boot application with 2 data sources. I do not think this is the problem here, but I thought I would mention it.
@Configuration
@Component
@ConfigurationProperties("connection.jpa")
@EnableTransactionManagement
public class HibernateConnectionsConfiguration {
@Bean(name = "jpaDataSource")
@Primary
public DataSource jpaDataSource() {
return DataSourceBuilder.create().password(password).driverClassName(driverClassName).url(databaseUrl).username(username).build();
}
@Bean
public DaoFactory getDaoFactory() {
EntityManagerFactory emf = entityManagerFactory();
DaoFactory f = new DaoFactory(emf);
System.out.println("DAO FACTORY IN Bean CONSRUCTOR:"+f);
return f;
}
Now the logs clearly say that the DaoFactory is NOT null and seems to be instantiated correctly.
I have this other class where I try and autowire that bean. Please note that I am trying to import the DaoFactory bean and none of the DataSources. There is only one DaoFactory @Bean
public class ECServiceFactory implements IServiceFactory {
private Map<String,String> props = null;
private final User rootUser;
private final WorkflowExecutionManager workflowExecutionManager;
private ElasticSearchService elasticSearchService;
private final Class<? extends Exception> securityException;
private final Configuration cmsConfig;
private VersionedDocumentService documentService;
@Autowired
DaoFactory daoFactory;
public ECServiceFactory(Map<String,String> props,
VersionedDocumentService documentServiceClass,
User rootUser,
Class<? extends Exception> securityException,
Configuration configuration) {
this.documentService = documentServiceClass;
this.props = props;
this.rootUser = rootUser;
this.workflowExecutionManager = new WorkflowExecutionManager(60, 100);
System.out.println("DAO Factory from SERVICE Facory:"+daoFactory);
this.elasticSearchService = new ElasticSearchService(daoFactory);
this.securityException = securityException;
this.cmsConfig = configuration;
}
Now the logs clearly state the the DAO Facotry from Service Factory: is NULL
Now the class that instantiates my ECServiceFactory is in my Application.java class, --- However, I have that class implement ApplicationListener and the method looks like this:
@SuppressWarnings("unchecked")
@Override
public void onApplicationEvent(ApplicationReadyEvent arg0) {
ECServiceFactory svcFactory = new ECServiceFactory(application, documentService,new SuperUser(),AccessDeniedException.class,config);
}
So it seems to me that all the beans have been loaded at this point and I should not have any problems with my Autowire.
What am I doing wrong?