BeanCreationException – Exception encountered during context initialization – cancelling refresh attempt

I have recently learning Spring to be specific Spring ORM. I am getting some errors from my code, I am not getting where I am going wrong though i have all instruction of the tutorial.

Here are java and configuration files:

com.spring.orm.Main.java file

package com.spring.orm;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.spring.orm.dao.StudentDao;
import com.spring.orm.entities.Student;

public class Main 
{
    private static ApplicationContext context;

    public static void main( String[] args )
    {
        
        context = new ClassPathXmlApplicationContext("XML/config.xml");
        StudentDao obj1 = context.getBean("studentDao",StudentDao.class);
        
        Student s1 = new Student(1,"Sudheer Mishra","Surat");
        
        int insert = obj1.insert(s1);
        if(insert > 0) {
            System.out.println("data successfully inserted");
        }System.out.println("something went wrong");
        
    }
}

com.spring.orm.entities.Student.java file



package com.spring.orm.entities;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;

@Entity
@Table(name = "student_details")
public class Student {

    @Id
    @Column(name = "studentId")
    private int studentId;

    @Column(name = "studentName")
    private String studentName;

    @Column(name = "studentCity")
    private String studentCity;

    public Student() {
        super();
    }

    public Student(int studentId, String studentName, String studentCity) {
        super();
        this.studentId = studentId;
        this.studentName = studentName;
        this.studentCity = studentCity;
    }

    public int getStudentId() {
        return studentId;
    }

    public void setStudentId(int studentId) {
        this.studentId = studentId;
    }

    public String getStudentName() {
        return studentName;
    }

    public void setStudentName(String studentName) {
        this.studentName = studentName;
    }

    public String getStudentCity() {
        return studentCity;
    }

    public void setStudentCity(String studentCity) {
        this.studentCity = studentCity;
    }

}

com.spring.orm.dao.StudentDao.java file

package com.spring.orm.dao;

import org.springframework.orm.hibernate5.HibernateTemplate;

import com.spring.orm.entities.Student;

import jakarta.transaction.Transactional;

public class StudentDao {
    
    private HibernateTemplate hibernateTemplate;
    
    @Transactional
    public int insert(Student student) {
        int i = (int) this.hibernateTemplate.save(student);
        /* HibernateTemplate has all the CRUD operation methods */
        return i;
    }

    public HibernateTemplate getHibernateTemplate() {
        return hibernateTemplate;
    }

    public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
        this.hibernateTemplate = hibernateTemplate;
    }
    
}

config.xml (which i have kept in src/main/resources/XML folder)

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:util="http://www.springframework.org/schema/util"
    xsi:schemaLocation="all_schema_url_not adding because of question spam error">


    <!-- for enabling all annotations in spring... -->
    <context:annotation-config />

    <tx:annotation-driven />


    <!-- data source bean -->
    <bean
        class="org.springframework.jdbc.datasource.DriverManagerDataSource"
        name="ds">
        <property name="driverClassName"
            value="com.mysql.cj.jdbc.Driver" />
        <property name="url"
            value="jdbc:mysql://localhost:3306/cwdPrac" />
        <property name="username" value="root" />
        <property name="password" value="Root" />
    </bean>


    <!-- Local session factory bean -->
    <bean name="factory"
        class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
        <!-- data source -->
        <property name="dataSource" ref="ds"></property>
        <!-- hibernate properties -->
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQL8Dialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
            </props>
        </property>
        <!-- Annonated classes -->
        <property name="annotatedClasses">
            <list>
                <value>com.spring.orm.entities.Student</value>
            </list>
        </property>
    </bean>



    <!-- Hibernate template bean for Dao class -->
    <bean class="org.springframework.orm.hibernate5.HibernateTemplate"
        name="hibernateTemplate">
        <property name="sessionFactory" ref="factory"></property>
    </bean>


    <!--Dao class -> data access object layer -->
    <bean class="com.spring.orm.dao.StudentDao" name="studentDao">
        <property name="hibernateTemplate" ref="hibernateTemplate" />
    </bean>
    <!-- This is our Bottom-Up approach from DAO->HibernateTemplate->Local Session 
        Factory Bean->Data Source Bean -->


    <bean
        class="org.springframework.orm.hibernate5.HibernateTransactionManager"
        name="transactionManager">
        <property name="sessionFactory" ref="factory"></property>
    </bean>


</beans>

When I am running my Main.java I’m getting on my console

"Aug 06, 2024 6:04:25 PM org.springframework.context.support.AbstractApplicationContext refresh
WARNING: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'factory' defined in class path resource [XML/config.xml]: org/springframework/core/type/classreading/ClassFormatException
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'factory' defined in class path resource [XML/config.xml]: org/springframework/core/type/classreading/ClassFormatException
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1770)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:598)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:520)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:967)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:941)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:608)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:144)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:85)
    at com.spring.orm.Main.main(Main.java:21)
Caused by: java.lang.NoClassDefFoundError: org/springframework/core/type/classreading/ClassFormatException
    at org.springframework.orm.hibernate5.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:495)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1816)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1766)
    ... 12 more
Caused by: java.lang.ClassNotFoundException: org.springframework.core.type.classreading.ClassFormatException
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
    ... 15 more

I had checked what I can but not able to come up with this error, not getting that what I am missing here.

Is there any jars which I have not added ? or another configuration is still pending..

If anyone have any idea please help.

Eclipse Version: 2023-09 (4.29.0)

Build id: 20230907-1323

Thank you

If anyone have any idea, I’ll be grateful for their help. I’m getting that what I am missing here any jars or configuration of my entities. But I have followed exact same path as the tutorial. But still getting this error on console.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật