Gradle创建Spring Boot项目——1配置

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介: Gradle创建Spring Boot项目

第一步,创建项目并配制build.gradle文件

通过Intellij IDEA新建一个Gradle项目

在build.gradle文件中添加项目配制,执行一次Refresh all Gradle Projects

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

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'

version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

repositories {
	mavenCentral()
}


dependencies {
	compile "org.springframework.boot:spring-boot-starter"
	compile 'org.springframework.boot:spring-boot-starter-actuator'
	compile 'org.springframework.boot:spring-boot-starter-web'
	compile 'org.springframework.boot:spring-boot-starter-data-jpa'
	compile 'org.springframework.boot:spring-boot-starter-amqp'
	compile 'org.springframework.boot:spring-boot-starter-integration'
	compile 'org.springframework.integration:spring-integration-file:4.3.5.RELEASE'
	compile 'org.springframework.boot:spring-boot-devtools'
	compile 'mysql:mysql-connector-java'
	compile 'com.google.code.gson:gson:2.8.0'
	compile "io.springfox:springfox-swagger-ui:2.2.2"
	compile "io.springfox:springfox-swagger2:2.2.2"
	testCompile("org.springframework.boot:spring-boot-starter-test")
}
————————————————————————————————————

   

—————————————————————————————————————

第二步,配制application.yml文件

server:
  port: 8081
  context-path: /api/

spring:
  datasource:
    driverClassName: com.mysql.jdbc.Driver
    url: jdbc:mysql://192.168.1.108:3306/test2?characterEncoding=utf8&useSSL=false
    username: cm
    password: cm8888
    initialSize: 5
    minIdle: 5
    maxActive: 20

  jpa:
    hibernate:
      ddl-auto: update
      naming:
        strategy: org.hibernate.cfg.ImprovedNamingStrategy
    show-sql: true
    database: mysql

logging:
  file: springboot.log

第三步,添加Application.java文件

package com.wuti;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.ApplicationContext;

/**
 * Created by wtrover on 2017/6/23.
 */
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
    @Autowired
    ApplicationContext context;
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(Application.class);
    }
    public static void main(String[] args) throws Exception {
        SpringApplication.run(Application.class, args);
    }
}

到这里所有的配置就完成了。




相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
19天前
|
存储 Java 数据安全/隐私保护
|
4天前
|
安全 Java 开发者
深入理解Spring Boot配置绑定及其实战应用
【4月更文挑战第10天】本文详细探讨了Spring Boot中配置绑定的核心概念,并结合实战示例,展示了如何在项目中有效地使用这些技术来管理和绑定配置属性。
11 1
|
2天前
|
XML Java 数据格式
Spring高手之路18——从XML配置角度理解Spring AOP
本文是全面解析面向切面编程的实践指南。通过深入讲解切面、连接点、通知等关键概念,以及通过XML配置实现Spring AOP的步骤。
21 6
Spring高手之路18——从XML配置角度理解Spring AOP
|
3天前
|
消息中间件 JSON Java
RabbitMQ的springboot项目集成使用-01
RabbitMQ的springboot项目集成使用-01
|
3天前
|
消息中间件 开发框架 Java
什么是Spring Boot 自动配置?
Spring Boot 是一个流行的 Java 开发框架,它提供了许多便利的功能和工具,帮助开发者快速构建应用程序。其中一个最引人注目的特性是其强大的自动配置功能。
8 0
|
6天前
|
Java Spring
Spring文件配置以及获取
Spring文件配置以及获取
13 0
|
7天前
|
Java
springboot项目出现Exception in thread “main“ java.lang.NoClassDefFoundError: javax/servlet/Filter
springboot项目出现Exception in thread “main“ java.lang.NoClassDefFoundError: javax/servlet/Filter
13 0
|
7天前
|
XML Java Android开发
gradle配置
gradle配置
18 0
|
8天前
|
XML Java 数据格式
Spring 项目如何使用AOP
Spring 项目如何使用AOP
22 2
|
8天前
|
Java Spring
Spring boot项目如何发送邮件
Spring boot项目如何发送邮件
17 2