org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [com/itnull/xunwu/config/JPAConfig.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is java.lang.IllegalArgumentException: jdbcUrl is required with driverClassName.
问题原因:数据源配置项未获取,多数都是配置问题。
@Bean
@ConfigurationProperties(prefix="spring.datasource")
public DataSource dataSource() {
// return DataSourceBuilder.create().driverClassName("com.mysql.cj.jdbc.Driver")
// .password("root")
// .username("root")
// .url("jdbc:mysql://localhost:3306/learn?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=GMT&useSSL=false")
// .build();
return DataSourceBuilder.create().build();
}