1.這裏將介紹比較原始的方法。idea 2017.1,當你的jdk是1.8是很好創建springboot項目的,只要通過idea 的spring initial即可方便的創建,這裏我的是1.7,因此還沒找到怎麼通過該方法創建springboot項目。
jdk1.7創建Springboot項目,這裏你需要先配置在Idea 上配置maven,如下所示。
下面創建一個module,類似在eclipse下的工作空間創建一個project。而idea上的project 類似eclipse上的工作空間
得到的結果如下所示
引入springboot依賴,如果你是新建module,在這個module的父包project中引入了,則該module中的pom.xml不用引入如下的依賴。
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.7</java.version>//注意設定java版本
</properties>
<!-- Add typical dependencies for a web application -->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.7.RELEASE</version>//注意這裏我的jdk版本時1.7因此需要對應springboot的版本,其實這裏也可以用別的版本例如1.5.9,但是不能用1.5.19和最新版的2以上的版本(自己測試的就這麼多)
<relativePath/>
</parent>
在該module下新建controller和application類
對應代碼爲HelloApplication
package app;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
/**
* hello Created by pingf
*
* @Date 2019/1/10 - 10:55 .
*/
@SpringBootApplication
@ComponentScan(value = "controller")
public class HelloApplication {
public static void main(String[] args){
SpringApplication.run(HelloApplication.class,args);
}
}
HelloController代碼
package controller;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* hello Created by pingf
*
* @Date 2019/1/10 - 10:52 .
*/
@RestController
@EnableAutoConfiguration
public class Hellocontroller {
@RequestMapping("/hello")
public String hello(){
return "hello world idea";
}
}
啓動項目即可。最後的 結果爲