【问题标题】:ClassNotFound Exception when using Spring MVC 3.2.4 in multi-module maven project在多模块 maven 项目中使用 Spring MVC 3.2.4 时出现 ClassNotFound 异常
【发布时间】:2013-09-29 01:32:14
【问题描述】:

我有一个具有以下结构的项目: 父模块 - 常见的 --持久性 - 服务 --web_ui 在 parent_module 中,我定义了外部项目依赖项和属性,如 spring-mvc、spring-social、spring-data、hibernate 等。持久化模块具有实体定义和存储库。所有存储库都从 spring data 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>{
}

提前感谢您的任何建议。

【问题讨论】:

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


    【解决方案1】:

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

    2-clean project ,在很多情况下你需要删除maven性质并在改变项目面后再次添加

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

    再次设置 4 组网络服务器运行时间

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-11-13
        • 2013-12-15
        • 2016-09-13
        • 2016-06-13
        • 1970-01-01
        • 1970-01-01
        • 2015-10-10
        • 2017-08-13
        相关资源
        最近更新 更多