Springboot配置data jpa後啓動失敗報No qualifying bean of ty

錯誤1:java

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'email.tianlangstudio.aliyun.com.portal.repo.IAppRepo' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=appRepo)}spring

at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1695)app

at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1253)ide

at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1207)ui

at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640)spa

... 42 morehibernate

錯誤2:orm

Caused by: java.lang.IllegalArgumentException: Not a managed type: class email.tianlangstudio.aliyun.com.portal.model.Appget

at org.hibernate.metamodel.internal.MetamodelImpl.managedType(MetamodelImpl.java:582)it

at org.hibernate.metamodel.internal.MetamodelImpl.managedType(MetamodelImpl.java:85)

at org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation.<init>(JpaMetamodelEntityInformation.java:74)

at org.springframework.data.jpa.repository.support.JpaEntityInformationSupport.getEntityInformation(JpaEntityInformationSupport.java:66)

at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getEntityInformation(JpaRepositoryFactory.java:211)

at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:161)

at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:144)

at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:69)

at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:312)

at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet$5(RepositoryFactoryBeanSupport.java:297)

at org.springframework.data.util.Lazy.getNullable(Lazy.java:212)

*/

 

錯誤1是由於:Repositories掃描包配置錯誤

@Configuration

@EnableJpaRepositories(value = "email.tianlangstudio.aliyun.com.email.analysis",

        entityManagerFactoryRef = "masterEntityManagerFactory",

        transactionManagerRef = "masterTransactionManager")

 

錯誤2是由於EntityManagerFactory裏的model包名忘記修改,應該修改成model所在包

@Bean(name = "masterEntityManagerFactory")

@Primary

public EntityManagerFactory masterEntityManagerFactory() {

    HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();

    LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();

    factory.setJpaVendorAdapter(vendorAdapter);

    factory.setPackagesToScan("email.tianlangstudio.aliyun.com.email.analysis");

    factory.setDataSource(masterDataSource);//數據源

    factory.setJpaPropertyMap(jpaProperties.getProperties());

    factory.afterPropertiesSet();//在完成了其它全部相關的配置加載以及屬性設置後,才初始化

    return factory.getObject();

}

相關文章
相關標籤/搜索