另一个My autowired bean是null

时间:2018-01-30 08:15:40

标签: java spring spring-boot autowired

我有这个看起来基本上是这样的组件: - 请注意,我正在尝试使用带有2个数据源的Spring启动应用程序。我不认为这是问题,但我想我会提到它。

[routerLink]="['first-tenant', 'protected']"

现在日志清楚地说DaoFactory不是null并且似乎是正确实例化的。

我有另一个类,我尝试并自动装配该bean。请注意,我正在尝试导入DaoFactory bean而不是任何DataSources。只有一个DaoFactory @Bean

@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;
}

现在,日志清楚地显示来自Service Factory的DAO Facotry:是NULL

现在实例化我的ECServiceFactory的类在我的Application.java类中,---但是,我有该类实现ApplicationListener,方法如下所示:

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;
}

所以在我看来,此时已经加载了所有bean,我的Autowire不应该有任何问题。

我做错了什么?

0 个答案:

没有答案