O、README
起码需要了解 Maven的基本使用
IDE 无所谓 idea,eclipse均可
一、我的环境
1、java version "1.8.0_201"
2、Apache Maven 3.5.4
1) setting.xml 中的设置
<profile>
<id>jdk-1.8</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
</profile>
3、idea 2018.3.3
4、SpringBoot 2.0.5.RELEASE
二、快速开始
PART I - 开发/测试
1、创建一个maven工程(jar)
2、pom中导入依赖
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
3、编写启动程序
@SpringBootApplication
public class ProcessMainApplication {
public static void main(String[] args) {
SpringApplication.run(ProcessMainApplication.class, args);
}
}
4、编写Controller
@Controller
public class HelloController {
@ResponseBody
@RequestMapping("/hello")
public String hello(){
return "Hello World!";
}
}
5、run 启动程序 ProcessMainApplication.java
6、浏览器访问 http://localhost:8080/hello
PART II - 部署
1、pom.xml
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
2、双击下图 package 开始打包
打出的jar文件 在 target/xxxx.jar
3、java -jar xxxx.jar
三、其他
可以将上述搭建过程自动化 但还有必要了解这个自动化的过程