Springboot项目快速启动,IDEA
1.打开idea,点击file->New->Project
2.选择maven,选中自己配置好的jdk,这里用的是jdk8,然后点击next
3.定义项目名字,项目路径,然后点击finish项目创建好了,接下来对springboot进行配置
4.如图,是创建好的项目
5.接下来配置pom.xml由于这里只是进行springboot项目的启动,所以没有添加其他依赖
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.example</groupId> <artifactId>springdemo</artifactId> <version>1.0-SNAPSHOT</version> <!-- 定义公共资源版本 --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.1.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
6.刷新pom,等待依赖
7.写springboot入口,在src->main->java下创建一个SpringbootApplication.java,并写入如下代码
import org.springframework.boot.SpringApplication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class SpringbootApplication {
@RequestMapping("/quick")
@ResponseBody
public static void main(String[] args) {
SpringApplication.run(SpringbootApplication.class);
}
}
8.在src->main->java下创建包为com.icss.controller的QuickController.java文件,并写入如下代码
package com.icss.controller; public class QuickController { public String Quick(){ return "hello springboot"; } }
10.运行springboot项目
11.注意,此时有可能tomcat出错,若出错,在resources下创建application.properties文件,修改端口号就好了
server.port=8082
12.出现如下标志,说明服务已经启动
13.在浏览器中输入http://localhost:8082/quick
14.springboot快速启动已经成功了。