idea创建gradle构建springboot工程记录

花了一些时间,整合了一下idea创建gradle构建的springboot2工程,现记录如下:

下载的idea-2018.3.1,下载好后,去找个破解码就可以用了。

plugins里面安装lombok插件,这个可以简化java代码。

创建springboot工程,

新建工程spring initalizr,定义你硬盘上的jdk目录,custom,定义为http://start.spring.io/

选择gradle工程即可。

gradle脚本代码:如下:build.gradle

buildscript {
    ext {
        springBootVersion = '2.1.1.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

group = 'com.zyujie'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

repositories {
    mavenCentral()
}


dependencies {
    implementation('org.springframework.boot:spring-boot-starter-web')
    testImplementation('org.springframework.boot:spring-boot-starter-test')
}


dependencies {
    compile('org.springframework.boot:spring-boot-starter-web')
    testCompile('org.springframework.boot:spring-boot-starter-test')

    //数据源
    compile 'com.alibaba:druid-spring-boot-starter:1.1.10'
    compile 'mysql:mysql-connector-java:6.0.6'
    //配置mybatis
    compile "org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.1"
    //mybatis-generator core 包
    compile group: 'org.mybatis.generator', name: 'mybatis-generator-core', version:'1.3.2'

    //lombok
    compileOnly 'org.projectlombok:lombok:1.18.2'

    //swagger
    compile('io.springfox:springfox-swagger2:2.8.0')
    compile('io.springfox:springfox-swagger-ui:2.8.0')

    compile('com.fasterxml.jackson.core:jackson-databind:2.9.5')
    compile('com.fasterxml.jackson.core:jackson-core:2.9.5')
    compile('com.fasterxml.jackson.core:jackson-annotations:2.9.5')

    compile('org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.2')
    compile('mysql:mysql-connector-java')
    compile('com.alibaba:druid-spring-boot-starter:1.1.9')
    compile('com.github.pagehelper:pagehelper-spring-boot-starter:1.2.3')
}

 application.yml

#server端口 、 及次路径、tomcat字符集编码
server:
  port: 8888
  tomcat:
    uri-encoding: UTF-8
  servlet:
    context-path: /demo-one
#启用shutdown不需要验证
#endpoints:
#  shutdown:
#      enabled: true
#      sensitive: false
#      path: /basic/system/shutdown
spring:
  # REDIS (RedisProperties)
  # Redis数据库索引(默认为0)
  #  redis:
  #      database: 11
  ## Redis服务器地址 127.0.0.1
  #      host: 127.0.0.1
  ## Redis服务器连接端口
  #      port: 6379
  ## Redis服务器连接密码(默认为空)
  #      password:
  #      pool:
  ## 连接超时时间(毫秒)
  #        timeout: 0
  # AOP
  aop:
    proxy-target-class: true
    auto: true
  # 数据源配置
  #文件上传大小配置
  multipart:
    maxFileSize: 500Mb
    maxRequestSize: 1024Mb
  mvc:
    #出现错误时, 直接抛出异常
    throw-exception-if-no-handler-found: true
    #resources:
    #不要为我们工程中的资源文件建立映射
    #add-mappings: false
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://127.0.0.1:3306/demo?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
    username: root
    password: root
    # 下面为连接池的补充设置,应用到上面所有数据源中
    # 初始化大小,最小,最大
    initialSize: 5
    minIdle: 5
    maxActive: 20
    # 配置获取连接等待超时的时间
    maxWait: 60000
    # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
    timeBetweenEvictionRunsMillis: 60000
    # 配置一个连接在池中最小生存的时间,单位是毫秒
    minEvictableIdleTimeMillis: 300000
    validationQuery: SELECT 1 FROM DUAL
    testWhileIdle: true
    testOnBorrow: false
    testOnReturn: false
    # 打开PSCache,并且指定每个连接上PSCache的大小
    poolPreparedStatements: true
    maxPoolPreparedStatementPerConnectionSize: 20
    # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙,此处是filter修改的地方
    filters:
      commons-log.connection-logger-name: stat,wall,log4j
    # 通过connectProperties属性来打开mergeSql功能;慢SQL记录
    connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
    # 合并多个DruidDataSource的监控数据
    useGlobalDataSourceStat: true

  #druid登录
  #  druid:
  #    login:
  #      username :  admin
  #      password :  123456
  #  freemarker:
  #    template-loader-path: classpath:/templates/
  #    suffix: .html
  #    templateEncoding: UTF-8
  #    content-type: text/html
  #    static-path-pattern: classpath:/static/**
  #这句不加,有可能要报错
  jackson:
    serialization:
      FAIL_ON_EMPTY_BEANS: false

# mybatis配额
mybatis:
  typeAliasesPackage: com.zyujie.**.entity
  mapperLocations: classpath:/mybatis/conf/**/*.xml
  configLocation: classpath:/mybatis/sqlConfig.xml

pagehelper:
  helperDialect: mysql
  reasonable: true
  supportMethodsArguments: true
  pageSizeZero: true
  params: count=countSql

  #日志
logging:
  config: classpath:logback-spring.xml

 其它就不写了,配置mybatis,redis这些即可,工程实例可以从资料里下载:

https://download.csdn.net/download/zyujie/10860075

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值