springframeworkguru / spring-core-spring-mvc

115 stars 478 forks source link

Can't get it to run... #21

Open j0sevargas opened 5 years ago

j0sevargas commented 5 years ago

I'm doing the Spring Course on Udemy, but cant get it to run. I keep getting a huge error message which I believe is related to hibernate. I managed to make it run by explicitly adding the newest hibernate versions as dependencies in the pom.xml, but It won't load the entity beans into the H2 database.... Please help!.

2019-01-13 23:45:28.819 ERROR 13252 --- [ restartedMain] o.s.boot.SpringApplication : Application startup failed

org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tomcatEmbeddedServletContainerFactory' defined in class path resource [org/springframework/boot/autoconfigure/web/EmbeddedServletContainerAutoConfiguration$EmbeddedTomcat.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.boot.autoconfigure.web.ServerProperties org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration.properties; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serverProperties' defined in class path resource [org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfiguration.class]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org.hibernate.internal.CoreMessageLogger

j0sevargas commented 5 years ago

Solved! Didn't realize it was already solved. Just adding the following to the pom.xml does the trick:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>5.4.0.Final</version>
</dependency>

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>5.4.0.Final</version>
</dependency>

<dependency>
    <groupId>org.hibernate.javax.persistence</groupId>
    <artifactId>hibernate-jpa-2.0-api</artifactId>
    <version>1.0.1.Final</version>
</dependency>

Also making sure the URL calls for the "testdb" database. "jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1"