类文件org / springframework / orm / jpa / vendor / SpringHibernateJpaPersistenceProvider中的方法名称和签名重复

时间:2018-09-01 15:26:00

标签: java hibernate spring-mvc spring-data-jpa

我正在使用Spring MVC并尝试使用Spring Data JPA和Hibernate作为JPA供应商连接到MySQL数据库。我在配置JPA配置文件中遇到此错误:

从Apache日志:

 Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.orm.jpa.JpaVendorAdapter]: Factory method 'jpaVendorAdapter' threw exception; nested exception is java.lang.ClassFormatError: Duplicate method name&signature in class file org/springframework/orm/jpa/vendor/SpringHibernateJpaPersistenceProvider
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:582)
    ... 92 more
Caused by: java.lang.ClassFormatError: Duplicate method name&signature in class file org/springframework/orm/jpa/vendor/SpringHibernateJpaPersistenceProvider
    at java.base/java.lang.ClassLoader.defineClass1(Native Method)
    at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1007)
    at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
    at org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2352)
    at org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:833)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1278)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1138)
    at org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter.<init>(HibernateJpaVendorAdapter.java:80)
    at collaboration.config.SpringDataJpaConfig.jpaVendorAdapter(SpringDataJpaConfig.java:56)
    at collaboration.config.SpringDataJpaConfig$$EnhancerBySpringCGLIB$$39a885b5.CGLIB$jpaVendorAdapter$4(<generated>)
    at 

这是SpringDataJPA配置类:

@Configuration
@EnableJpaRepositories("collaboration.data.db")
@EnableTransactionManagement
public class SpringDataJpaConfig {
    @Bean
    public DataSource dataSource() {
        DriverManagerDataSource dataSource
                = new DriverManagerDataSource();
        dataSource.setDriverClassName("com.mysql.jdbc.Driver");
        dataSource.setUrl("jdbc:mysql://localhost:3306/collaboration");
        dataSource.setUsername("collaboration");
        dataSource.setPassword("password");
        return  dataSource;
    }


    @Bean
    @Autowired
    public PlatformTransactionManager transactionManager(EntityManagerFactory emf){
        JpaTransactionManager transactionManager = new JpaTransactionManager();
        transactionManager.setEntityManagerFactory(emf);
        return transactionManager;
    }

    @Bean
    public JpaVendorAdapter jpaVendorAdapter() {
        HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
        adapter.setDatabase(Database.MYSQL);
        adapter.setShowSql(false);
        adapter.setGenerateDdl(true);
        return adapter;
    }

    @Bean
    public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
        LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean();
        emf.setDataSource(dataSource());
        emf.setPersistenceUnitName("collaboration");
        emf.setJpaVendorAdapter(jpaVendorAdapter());
        emf.setJpaProperties(jpaProperties);
        return emf;
    }



    @Bean
    public PersistenceExceptionTranslationPostProcessor exceptionTranslation(){
        return new PersistenceExceptionTranslationPostProcessor();
    }   
}

编辑:这是我的build.gradle文件:

group 'com.example'
version '1.0-SNAPSHOT'

apply plugin: 'war'
apply plugin: 'java'

sourceCompatibility = 1.8

repositories {

    mavenCentral()
}

dependencies {
    compile "org.springframework:spring-webmvc:$springVersion"

    compile "org.springframework.security:spring-security-config:$springSecurityVersion"
    compile "org.springframework.security:spring-security-web:$springSecurityVersion"
    compile "org.springframework:spring-context:$springVersion"
    compile "org.springframework:spring-orm:$springVersion"
    compile "org.springframework.data:spring-data-jpa:$springDataJpaVersion"
    compile "org.hibernate:hibernate-core:$hibernateCore"
    compile "javax.inject:javax.inject:1"


    //data validation
    compile "org.hibernate:hibernate-validator:5.4.1.Final"
    compile group: 'javax.validation', name: 'validation-api', version: '2.0.1.Final'


    // https://mvnrepository.com/artifact/commons-beanutils/commons-beanutils
    compile group: 'commons-beanutils', name: 'commons-beanutils', version: '1.9.3'

    // https://mvnrepository.com/artifact/mysql/mysql-connector-java
    compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.12'




    // thymleaf dependencies
    compile "org.thymeleaf:thymeleaf-spring5:$thymleafSpring5Version"
    compile group: 'org.thymeleaf.extras', name: 'thymeleaf-extras-springsecurity4', version: '3.0.2.RELEASE'

    //bootstrap
    compile "org.webjars:bootstrap:$bootstrapVersion"

    providedCompile "javax.el:javax.el-api:$jspElVersion"
    providedCompile "javax.servlet:javax.servlet-api:$javaxServletApi"

    testCompile group: 'junit', name: 'junit', version: '4.12'
    testCompile "junit:junit-dep:$junitVersion"
    testCompile "org.springframework:spring-test:$springVersion"
    testCompile "org.mockito:mockito-core:$mockitoVersion"
    testCompile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.25'



    //selenium driver
    compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.12.0'
    compile group: 'org.seleniumhq.selenium', name: 'selenium-chrome-driver', version: '3.12.0'


}


task wrapper(type: Wrapper) {
    gradleVersion = '4.1'
}

war {
    baseName = 'collaboration'
}

任何想法可能是由什么引起的?

0 个答案:

没有答案