引起:java.lang.IllegalStateException:没有从{classpath *:META-INF / persistence.xml}解析的持久性单元

问题描述 投票:0回答:1

我在配置中有这个bean

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

如何解决问题?

多谢!

java spring hibernate spring-boot orm
1个回答
0
投票

您应该将以下内容提供给@EnableJpaRepositories注释

@EnableJpaRepositories(entityManagerFactoryRef = "defaultEntityManager", transactionManagerRef = "defaultTransactionManager",
    basePackages = {"<complete package to dao package>"})
© www.soinside.com 2019 - 2024. All rights reserved.