1. 程式人生 > 實用技巧 >Java爬坑日記之Error creating bean with name 'testController': Injection of resource dependencies failed

Java爬坑日記之Error creating bean with name 'testController': Injection of resource dependencies failed

報錯如下:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bookRepository' defined in com.sirifeng.testjpa.Mapper.BookRepository 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]

我吐了,de了兩個小時的bug,最後發現是資料庫的url的一個引數寫錯了,我寫的

spring.datasource.url=jdbc:mysql://localhost:3306/webstore?useUnicode=true&characterEncoding=utf-8&serverTimeZone=UTC


這裡的serverTimeZone,寫錯了,應該是serverTimezone,Z寫成大寫了,跟這報錯沒有半毛線關係,對新手來說真的太不友好了啊!!!!

所以寫程式碼的時候,特別是這種配置檔案的,一定要仔細檢查!!!