接博客---> Idea创建spring boot 项目(3)集成Lombok
使用工具:
IDE:idea 2017.2.6
Spirng boot:1.5.9
Swagger版本:2.7.0
Lombok版本:1.16.20
MySql版本:6.0.6
数据库连接池:HikariCP 2.7.7
1、添加依赖:
打开项目build.gradle文件,添加依赖如下:
buildscript {
ext {
springBootVersion = '1.5.9.RELEASE'//spring boot 版本
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
//添加资源库
repositories {
maven { url 'http://maven.aliyun.com/nexus/content/repositories/central' }//添加阿里仓库
mavenCentral()//添加Maven中央资源库
}
apply plugin: 'java'// 指定项目为java项目,项目编译(在项目提示符下执行:gradle build)时生成项目的jar包。
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'application'
group = 'com.demo'
version = '1.5.9-SNAPSHOT'
sourceCompatibility = 1.8
targetCompatibility = 1.8
mainClassName = 'com.tinckay.App'//告诉gradle启动类的路径
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
testCompile("org.springframework.boot:spring-boot-starter-test")
compile("org.springframework.boot:spring-boot-starter-tomcat")
compile("io.springfox:springfox-swagger2:2.7.0")//swagger2核心依赖
compile("io.springfox:springfox-swagger-ui:2.7.0")//为项目提供api展示及测试的界面
compile("org.projectlombok:lombok:1.16.20")//lombok依赖包
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("mysql:mysql-connector-java:6.0.6")//连接mysql数据库驱动
compile("com.zaxxer:HikariCP:2.7.7")//HikariCP 数据库连接池依赖
}
2、配置文件:
打开项目application.properties文件,配置如下信息:
注意:数据源的配置信息要配本机的;
#配置端口号 server.port=5252 #配置数据源 db.driver=com.mysql.jdbc.Driver db.username=test db.password= db.url=jdbc:mysql://127.0.0.1:3306/demo #Hibernate Configuration hibernate.naming.strategy=org.hibernate.cfg.DefaultComponentSafeNamingStrategy hibernate.dialect=org.hibernate.dialect.MySQLDialect hibernate.hbm2ddl.auto=none hibernate.connection.autocommit=

本文详细介绍了如何在Idea中创建一个Spring Boot项目,并整合Spring Data JPA,涉及添加依赖、配置文件设置、JPA配置类编写、数据库表创建、实体类和JPA接口设计,以及测试接口的步骤。示例使用了HikariCP作为数据源,配合Lombok简化代码,同时利用Swagger进行API文档展示。
最低0.47元/天 解锁文章
1万+

被折叠的 条评论
为什么被折叠?



