我有具有以下结构的项目: parent_module - 普通 --persistence --service --web_ui 在parent_module ,我定义了外部项目依赖性和属性,如spring-mvc,spring-social,spring-data,hibernate等。持久性模块具有实体定义和存储库。所有存储库都从弹簧数据JPARepository扩展而来。服务模块有一堆服务定义。 Web_ui具有所有网页和Spring配置。它也用于打包WAR文件。ClassNotFound的异常
所有包都基于一个pom.xml文件在同一个项目中。我正在使用spring java配置。该项目工作正常。但是我决定将它重构成不同的模块。因此,我将所有持久性包移到持久性模块,并对其他包执行相同的操作。
但是,我移动它们后,泉水容器无法启动。它抛出一个错误消息说ClassNotFoundException的:com.mycompany.SomeEntityRepo
@EnableJpaRepositories(basePackages = "com.mycompany.persistence.repo", repositoryImplementationPostfix="CustomImpl")
@EnableTransactionManagement
public class DatabaseConfig{
.....
@Bean
public EntityManagerFactory entityManagerFactory() {
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
vendorAdapter.setGenerateDdl(true);
vendorAdapter.setShowSql(true);
vendorAdapter
.setDatabasePlatform("org.hibernate.dialect.MySQL5InnoDBDialect");
vendorAdapter.setDatabase(Database.MYSQL);
LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
factory.setJpaVendorAdapter(vendorAdapter);
factory.setPackagesToScan(PACKAGE_TO_SCAN);
factory.setDataSource(dataSource());
factory.setPersistenceXmlLocation("classpath:META-INF/persistence.xml");
factory.setPersistenceUnitName("persistenceUnit");
Properties properties = new Properties();
properties
.setProperty("hibernate.cache.use_second_level_cache", "true");
properties.setProperty("hibernate.cache.region.factory_class",
"org.hibernate.cache.ehcache.EhCacheRegionFactory");
properties.setProperty("hibernate.cache.use_query_cache", "true");
properties.setProperty("hibernate.generate_statistics", "true");
factory.setJpaProperties(properties);
factory.afterPropertiesSet();
return factory.getObject();
}
}
库:
@Repository
public interface BookEntityRepo extends JpaRepository<BookEntity, Long>{
}
感谢提前任何建议。