springboot+hibernate+maven(模块化工程)搭建过程遇到的问题汇总
1.遇到的问题:
a.数据库连结篇:
使用技术为springboot提供的jpa技术,使用hibernate框架进行ORM操作,本人数据库版本偏高,此处遇到低版本的驱动无法连结到数据库的问题,解决方案,提高版本号:
UTF-8 8.0.12 mysql mysql-connector-java ${mysql.version}
接口层使用CrudRepository类的继承实现增删改查,此过程耗时最长,原因是springboot的Service模块需要该模块的接口访问数据库,springboot一直报错,最终得益于网友的一篇好文,提到在springboot的启动类中加入jpa注解@EnableJpaRepositories("org.teachPlateform.Dao") ,问题得以解决,最终项目的的启动类大概长这个样子
@SpringBootApplication
@ComponentScan("org.teachPlateform")
@EnableJpaRepositories("org.teachPlateform.Dao")
@EntityScan("org.teachPlateform.Domain")
public class App
{
public static void main( String[] args )
{
SpringApplication.run(App.class,args);
}
}
项目的结构长这个样子:
teachPlateform-Web结构:
配置文件application.yml:
spring:
datasource:
url: jdbc:mysql://localhost:3306/mydb?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
type: com.alibaba.druid.pool.DruidDataSource
username: xxx
password: xxx
driver-class-name: com.mysql.cj.jdbc.Driver
jpa:
hibernate:
ddl-auto: update
show-sql: true
最后项目存到百度云:
链接:https://pan.baidu.com/s/1Oh6a0hEigBsLgeUTlD6Xmw
提取码:vffz