由以下原因引起:java.lang.IllegalStateException:没有从{classpath *:META-INF / persistence.xml}

时间:2018-09-18 23:48:43

标签: java spring hibernate spring-boot orm

我在配置中有这个豆

   @Bean
public LocalContainerEntityManagerFactoryBean localContainerEntityManagerFactoryBean(
        DataSource dataSource    ) {
    LocalContainerEntityManagerFactoryBean bean = new LocalContainerEntityManagerFactoryBean();
    bean.setPackagesToScan("com.x");
    bean.setPersistenceUnitName("default");
    bean.setDataSource(dataSource);
    Properties hibernateProperties = new Properties();
    hibernateProperties.setProperty("hibernate.hbm2ddl.auto", "update");
    hibernateProperties.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQL94Dialect");
    bean.setJpaProperties(hibernateProperties);
    HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    bean.setJpaVendorAdapter(vendorAdapter);

    return bean;
}

这是春季靴子

@EnableJpaRepositories(basePackages = {"com.x"})
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class,
    HibernateJpaAutoConfiguration.class})

如何解决该问题?

非常感谢!

1 个答案:

答案 0 :(得分:0)

您应在@EnableJpaRepositories批注中提供以下内容

@EnableJpaRepositories(entityManagerFactoryRef = "defaultEntityManager", transactionManagerRef = "defaultTransactionManager",
    basePackages = {"<complete package to dao package>"})