# SpringBoot-環境搭建
- 2020 年 7 月 25 日
- 筆記
- JAVA, spring_boot
SpringBoot-環境搭建
標籤(空格分隔): java,SpringBoot
1.創建Maven工程
2.編寫pom文件
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.6</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
</dependency>
</dependencies>
3.編寫SpringBoot引導類
package com.itheima;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class MySpringBootApplication {
public static void main(String[] args) {
SpringApplication.run(MySpringBootApplication.class, args);
}
}
4.編寫Controller
package com.itheima.web;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.sql.DataSource;
@Controller
public class HelloController {
@Autowired
private DataSource dataSource;
@GetMapping("/hello")
@ResponseBody
public String hello() {
return "hello spring boot";
}
}
5.運行測試
6.注意事項
- JDK版本配置
- Maven倉庫配置