1.工具:Ecplise
2.jdk
3.下载maven
下载地址:https://maven.apache.org/
将下载文件解压在任意一个空文件夹内,项目文件结构如图(小编是下载maven3.3.3版本的)
4.ecplise配置maven
1.打开perferences,在installations中添加本地解压的maven,点击add,正确填写路径后,点击apply。
2.点击user setting选项。
*global setting配置你maven项目中的setting.xml文件,路径如下。
*usersetting配置你maven项目中的setting.xml文件。
*local repository选项填写本地的仓库(本地仓库默认在c盘里面,如下图二)
5.ecplise创建springboot项目
1.点击new project,选择maven项目,勾选creat a simple project,在填写项目的基本信息,最后点击finish完成项目创建。
6.springboot配置
pom.xml配置:
<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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>alian</groupId>
<artifactId>springboot-shiro</artifactId>
<version>0.0.1-SNAPSHOT</version>
</project>
目的:添加父工程依赖。
1.错误提示:pom.xml文件出现这样的错误提示。
在pom文件中添加。
<properties>
<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
</properties>
<!-- 原因:spring-boot,升级到2.1.5版本,而maven-jar-plugin.version插件默认版本不兼容所以报错,但不影响运行 -->
添加最后错误消失。
2.项目提示错误,无原因。
解决方案:点击project,打开properties,将下图标记两项选择为warring,点击apply后,在重启项目错误就可以消失,
3.添加springboot-web依赖,用于启动项目。
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
4.在src/main/java项目下面创建一个启动类
package alian;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringbootMybatisApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootMybatisApplication.class, args);
}
}
7.启动
在src/main/java项目下面创建一个clas类
package alian.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class TestController {
@RequestMapping("/test")
public @ResponseBody Object test()
{
return "hello the world!";
}
}
点击启动后,控制台出现的效果:
在浏览器访问:效果: