java.lang.IllegalStateException:未初始化LifecycleProcessor
我正在尝试使用Spring数据和H2数据库运行Spring MVC项目这是我当前的配置:java.lang.IllegalStateException:未初始化LifecycleProcessor,java,spring,spring-mvc,spring-data-jpa,spring-data,Java,Spring,Spring Mvc,Spring Data Jpa,Spring Data,我正在尝试使用Spring数据和H2数据库运行Spring MVC项目这是我当前的配置: package com.skillshare.project.config; import ... @Configuration @EnableJpaRepositories(basePackages = {"com.skillshare.project.dao"}) @EnableTransactionManagement public class PersistenceJPACo
package com.skillshare.project.config;
import ...
@Configuration
@EnableJpaRepositories(basePackages = {"com.skillshare.project.dao"})
@EnableTransactionManagement
public class PersistenceJPAConfig {
@Bean
public DataSource dataSource() {
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
EmbeddedDatabase db = builder
.setType(EmbeddedDatabaseType.H2) //.H2 or .DERBY
.build();
return db;
}
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
LocalContainerEntityManagerFactoryBean em
= new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource());
em.setPackagesToScan(new String[] { "model" });
JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter);
em.setJpaProperties(additionalProperties());
return em;
}
Properties additionalProperties() {
Properties properties = new Properties();
properties.setProperty("hibernate.hbm2ddl.auto", "create-drop");
properties.setProperty(
"hibernate.dialect", "org.hibernate.dialect.H2Dialect");
properties.setProperty("hibernate.hbm2ddl.import_files" ,"insert-data.sql");
return properties;
}
@Bean
public PlatformTransactionManager transactionManager(
EntityManagerFactory emf){
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(emf);
return transactionManager;
}
@Bean
public PersistenceExceptionTranslationPostProcessor exceptionTranslation(){
return new PersistenceExceptionTranslationPostProcessor();
}
}
但当我取消评论时,“EnableJpaRepository”的春天似乎并没有开始。配置有问题吗?您能不能比“似乎没有启动”更具体一些?您得到的错误的跟踪是什么?