0

I got this error when trying to create a Repository that extends CrudRepository using Spring Data Hibernate (not Spring Boot). As I'm new to Spring and Spring data, I really don't know what is the reason?

Exception in thread "main" java.lang.ExceptionInInitializerError
at main.main(main.java:52)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'issueRepository': Initialization of bean failed; nested exception is java.lang.AbstractMethodError
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:564)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:742)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:84)
at lle.crud.data.util.DataHibernateUtil.<clinit>(DataHibernateUtil.java:26)
... 1 more
Caused by: java.lang.AbstractMethodError
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:99)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:302)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:129)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1531)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1276)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
... 11 more

Here are the related files

The config:

@Configuration
@EnableTransactionManagement
@PropertySource(value = {"classpath:jdbc.properties"})
@ImportResource("classpath:applicationContext.xml")
@EnableJpaRepositories(basePackages = {"lle.crud.repository"})
public class AppConfig {

@Autowired
private Environment environment;

@Bean
public DataSource dataSource() {
    ComboPooledDataSource dataSource = new ComboPooledDataSource();
    try {
        dataSource.setDriverClass(environment.getRequiredProperty("jdbc.driverClassName"));
        dataSource.setJdbcUrl(environment.getRequiredProperty("jdbc.databaseurl"));
        dataSource.setUser(environment.getRequiredProperty("jdbc.username"));
        dataSource.setPassword(environment.getRequiredProperty("jdbc.password"));
    } catch (IllegalStateException | PropertyVetoException e) {
        e.printStackTrace();
    }
    return dataSource;
}

@Bean
public Properties getHibernateProperties() {
    Properties hibernateProperties = new Properties();
    hibernateProperties.put("hibernate.dialect", environment.getRequiredProperty("jdbc.dialect"));
    hibernateProperties.put("hibernate.show_sql", false);
    hibernateProperties.put("hibernate.c3p0.min_size", 5);
    hibernateProperties.put("hibernate.c3p0.max_size", 20);
    hibernateProperties.put("hibernate.c3p0.timeout", 300);
    hibernateProperties.put("hibernate.c3p0.max_statements", 50);
    hibernateProperties.put("hibernate.c3p0.idle_test_period", 3000);

    return hibernateProperties;
}

@Bean
public LocalSessionFactoryBean sessionFactory() {
    LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
    sessionFactory.setDataSource(dataSource());
    sessionFactory.setHibernateProperties(getHibernateProperties());
    sessionFactory.setConfigLocation(new ClassPathResource("hibernate.cfg.xml"));
    sessionFactory.setAnnotatedClasses(new Class<?>[] {
        Issue.class,
        Trade.class,
        TradeHeader.class,
        TradeIssueMap.class,
        User.class,
        Role.class,
        Status.class,
        Action.class,
        Audit.class,
        InputMx2.class,
        InputMx3.class
    });
    return sessionFactory;
}

@Bean
public HibernateTransactionManager transactionManager() {
    HibernateTransactionManager transactionManager = new HibernateTransactionManager();
    transactionManager.setSessionFactory(sessionFactory().getObject());
    return transactionManager;
}

@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
    em.setDataSource(dataSource());
    em.setPackagesToScan(new String[] { "lle.crud.model", "lle.crud.repository" });

    JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    em.setJpaVendorAdapter(vendorAdapter);

    return em;

} }

pom.xml

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <org.slf4j.version>2.10.0</org.slf4j.version>
    <org.hibernate.version>5.2.10.Final</org.hibernate.version>
    <org.hibernate-validator.version>6.0.2.Final</org.hibernate-validator.version>
    <org.springframework.version>4.3.13.RELEASE</org.springframework.version>

    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>

</properties>
<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>


    <!-- slf4j -->
    <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>${org.slf4j.version}</version>
    </dependency>
    <!-- slf4j -->

    <!-- Hibernate resources -->

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>${org.hibernate.version}</version>
    </dependency>

    <!-- Hibernate resources -->

    <!-- Spring -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>6.0.6</version>
    </dependency>



    <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-c3p0 -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-c3p0</artifactId>
        <version>5.2.12.Final</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
        <version>2.0.4.RELEASE</version>
    </dependency>

</dependencies>

The Repository

@Repository
public interface IssueRepository extends CrudRepository<Issue, Long>{

    public List<Issue> findAll();

}

Can anyone tell me what is happening here? Thank you in advance.

Ali Akbarpour
  • 958
  • 2
  • 18
  • 35
  • `AbstractMethodError` is almost always due to a mismatch between the version of a library on your build environment and the one on the server. Make sure you have the same version of EVERYTHING deployed in both places. – Jim Garrison Mar 12 '18 at 08:14
  • I really cannot find out where is the version mismatch, and I dont know what I need to find out here? Mismatch version between which ones? What does it mean "library on your build environment and the one on the server", here I have only one environment. –  Mar 12 '18 at 08:30
  • All the third party libraries and Java versions in both environments. – Jim Garrison Mar 12 '18 at 08:31
  • I only have one environment. What supposed to be having mismatch version? I literally have no idea which ones holding the mismatch version? For example how do we know Spring Core 4.x.x matches SomeThing 3.x.x or not? –  Mar 12 '18 at 08:39
  • If I'm searching for "Spring Data Hibernate Pom.xml", there is no sample that I can rely on to setup my project, what need to be in the pom when I want to do Spring Data, what version go with them, etc. It's really a headache when fixing configure-related problems like this. –  Mar 12 '18 at 08:41

0 Answers0