0

I wanted to follow the tutorial on the following link: Tutorial Spring MVC, but at runtime I received the following error message.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'applicantDAOImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory org.o7planning.springmvcforms.dao.impl.ApplicantDAOImpl.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in org.o7planning.springmvcforms.config.ApplicationContextConfig: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.hibernate.SessionFactory]: Factory method 'getSessionFactory' threw exception; nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException

Does anyone have an idea of the source of this error?

Thank you

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Dev Learning
  • 35
  • 1
  • 7
  • I'm not sure about the tutorial in the website as it is in French and lots of steps. You should follow a tutorial which has a workable git repository in Github or Gitlab so that you can simply clone and build. Then after cloning, normally you use Maven or Gradle to the build. This way, you can replicate exactly the same code and library with your tutor. Try spring boot first, before moving to Spring MVC. You can produce something faster with spring boot. That's my 2 cents. – fauzimh Feb 16 '22 at 14:33
  • @fauzimh, i puted a wrong link, it was corrected. thanks for replying – Dev Learning Feb 16 '22 at 14:49
  • Usually, this is a classpath issue. I.e., when you use maven in your project, you are most likely missing a dependency you need. I mostly find those by googling the technologies you use in your project (hibernate in this case), but you could also read the docs. – sinned Feb 16 '22 at 16:39

2 Answers2

0

A long time ago I've followed that tutorial and it worked for me :)

Based on the exception I would look at the DB configs in your project because it looks like Spring can't create Hibernate-related Beans. But first I would check some similar problems like your: How to resolve java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException

Good luck!

  • @Rusian Macari: thanks for you answer, i was using JDK 1.8 to build the project and it seems that javaxb is removed in this version so i aded it but now i get another error "Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection", do you have an idea about this error. thanks – Dev Learning Feb 16 '22 at 16:52
  • @DevLearning most likely the problem is related to DB configuration in your project, here is a similar problem and a possible solution: https://stackoverflow.com/questions/50775763/spring-could-not-open-hibernate-session-for-transaction-unable-to-acquire-jdbc – Ruslan Macari Feb 17 '22 at 13:43
0

Well, i Had Similar Issues with an old project from around 2019 plus

 <!-- https://mvnrepository.com/artifact/javax.xml.ws/jaxws-api -->
    <dependency>
    <groupId>javax.xml.ws</groupId>
    <artifactId>jaxws-api</artifactId>
    <version>2.2</version>
    </dependency>

i added this dependecy for javax, since it's the one responsible for the xml bindings that may be present in the project.

check here for more explanation https://www.jesperdj.com/2018/09/30/jaxb-on-java-9-10-11-and-beyond/