spring-guides / gs-accessing-data-mysql

Accessing data with MySQL :: Learn how to set up and manage user accounts on MySQL and how to configure Spring Boot to connect to it at runtime.
http://spring.io/guides/gs/accessing-data-mysql/
Apache License 2.0
201 stars 314 forks source link

Error creating bean with name 'userRepository' defined in com.example.accessingdatamysql.UserRepository #40

Closed AshhadS closed 4 years ago

AshhadS commented 4 years ago

I have cloned this repository and i get this error when trying to run the AccessingDataMysqlApplication.java file following your tutorial https://spring.io/guides/gs/accessing-data-mysql/

AshhadS commented 4 years ago
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository' defined in com.example.accessingdatamysql.UserRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Cannot resolve reference to bean 'jpaMappingContext' while setting bean property 'mappingContext'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment
dsyer commented 4 years ago

Works for me. Hard to tell what you did wrong with only a fragment of a stack trace. Is the database running? Did you set up the user account etc. as described in the tutorial?

AshhadS commented 4 years ago

@dsyer yes the user has been created following the same steps mentioned in the tutorial and I'm able to log in with those credentials as well. Screenshot (246) Here is the full stack trace of the error I'm getting when trying to run the AccessingDataMysqlApplication.java file Let me know if there is more information I could provide which would help you find what the actual issue is.

Error stack trace gist

dsyer commented 4 years ago

The stack trace suggests that hibernate can’t connect to the database. Check the URL and that you can connect from the same host/VM yourself?

AshhadS commented 4 years ago

@dsyer the database connections was the issue (I had the wrong port number in my db url). Greatly appreciate your prompt response on this!

If anyone else is having this same issue please check your db connections defined here src\main\resources\application.properties