structure

  1. $ mkdir -p microservice-demo
  2. $ microservice-demo
  3. $ gradle init --type=java-library
  1. $ tree
  2. .
  3. ├── build.gradle
  4. ├── gradle
  5. └── wrapper
  6. ├── gradle-wrapper.jar
  7. └── gradle-wrapper.properties
  8. ├── gradlew
  9. ├── gradlew.bat
  10. ├── settings.gradle
  11. └── src
  12. ├── main
  13. └── java
  14. └── Library.java
  15. └── test
  16. └── java
  17. └── LibraryTest.java
  18. 7 directories, 8 files

引入 spring-boot

  1. buildscript {
  2. repositories {
  3. mavenCentral()
  4. }
  5. dependencies {
  6. classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.3.RELEASE")
  7. }
  8. }
  9. apply plugin: 'java'
  10. apply plugin: 'idea'
  11. apply plugin: 'spring-boot'
  12. repositories {
  13. jcenter()
  14. }
  15. dependencies {
  16. compile 'org.slf4j:slf4j-api:1.7.13'
  17. compile "org.springframework.boot:spring-boot-starter-web:1.3.3.RELEASE"
  18. testCompile 'junit:junit:4.12'
  19. }
  1. $ gradle idea
  2. $ open microservice-demo.ipr

版本控制

  1. $ git init .
  2. $ touch .gitignore
  1. .gradle/
  2. build/
  3. microservice-demo.*
  4. out/

启动

创建应用程序入口

  1. package com.thoughtworks.microservice.demo;
  2. import org.springframework.boot.SpringApplication;
  3. import org.springframework.boot.autoconfigure.SpringBootApplication;
  4. @SpringBootApplication
  5. public class Application {
  6. public static void main(String[] args) {
  7. SpringApplication.run(Application.class, args);
  8. }
  9. }