ClassNotFound在多模块maven项目中使用Spring MVC 3.2.4时出现异常

时间:2013-09-24 01:04:14

标签: spring maven spring-mvc spring-data-jpa spring-social

我有一个具有以下结构的项目:   parent_module      - 共同     --persistence      - 服务     --web_ui 在parent_module中,我定义了外部项目依赖项和属性,如spring-mvc,spring-social,spring-data,hibernate等。持久性模块具有实体定义和存储库。所有存储库都从spring数据JPARepository扩展。服务模块有一堆服务定义。 Web_ui具有所有网页和Spring配置。它也用于打包WAR文件。

所有包都基于之前的一个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>{
}

感谢您提前获得任何建议。

2 个答案:

答案 0 :(得分:0)

1检查项目面(主要是jdk),使用sts Markers进行任何对比,并根据您的环境进行更改。

2-clean项目,在许多情况下,您需要删除maven性质并在更改项目面后再次添加

3次安装并再次生成源到目标

再次设置4套网络服务器

答案 1 :(得分:0)

我建议您将Hibernate Properties和SessionFactory配置到Spring Xml文件中并尝试检查Lib文件夹中的每个jar文件。 实际上我不确定这个,但这是由于类路径中的错误jar文件造成的。

相关问题