如何解决java.lang.IllegalStateException:LifecycleProcessor未初始化
我正在尝试使用spring数据和H2数据库运行Spring MVC项目,这是我当前的配置:
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”弹簧似乎没有开始。配置有问题吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。