我有具有以下結構的項目: 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>{
}
感謝提前任何建議。