启动主程序类,报告下面的异常:
Cannot determine embedded database driver class for database type NONE
原因:这是因为spring boot默认会加载org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration类,DataSourceAutoConfiguration类使用了@Configuration注解向spring注入了dataSource bean。因为工程中没有关于dataSource相关的配置信息,当spring创建dataSource bean因缺少相关的信息就会报错。有如下两种解决办法:
(1)在application.properties中配置数据源
server.port=8076
spring.datasource.url=jdbc:oracle:thin:@localhost:1521:orcl
spring.datasource.username=xxx
spring.datasource.password=yyy
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
(2)在主程序启动方法上的注解中去除默认数据源加载:
@SpringBootApplication(exclude={DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class})