最近用IDEA插件创建Springboot项目,总是403,估计被墙了!
那么这里在提供两种方法
1.从官网下载模板,导入IDEA内
2.使用Maven创建
方法一:打开 https://start.spring.io/ 选择Springboot版本 写上包名 项目命 点击Generate Project 下载项目导入IDEA。(这种方法下载的工程可能是SpringBoot java工程,检查SpringBootSpringBoot框架开发web项目的起步依赖是否带web spring-boot-starter-web 如第二张图,如果不带添加即可)
方法二:
通过Maven
(1)简单说一下创建,大概流程就是创建一个Maven项目,在pom文件里面添加SpringBoot父级依赖,启动依赖,启动测试依赖!
这里我用原型创建Maven项目
(2)在pom.xml里面添加 SpringBoot框架的父级依赖 SpringBoot框架开发web项目的起步依赖 测试依赖
添加好之后,在com.springboot包下创建类Application Springboot工程的主类(放在其他业务子类的外面)
编写main方法 加上注解
贴代码:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication //springboot的全局的自动配置注解
public class Application {
public static void main(String[] args) {
// 固定的代码 启动springboot程序 初始化spring容器
SpringApplication.run(Application.class, args);
}
}
创建一个controller 进行测试
右击Application类 DeBug运行
测试结果
pom文件完整配置:
<?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>
<!--继承了SpringBoot框架的父级依赖-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.demo.springboot</groupId>
<artifactId>01-springboot-web</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>02-springboot-mybatis</name>
<description>Demo project for Spring Boot</description>
<!--Maven属性配置-->
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!--SpringBoot框架开发web项目的起步依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--SpringBoot框架的起步测试依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- springboot 开发自动热部署 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<!--SpringBoot的打包编译插件-->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
具体配置内容可参考: https://www.cnblogs.com/shenlailai/p/10462828.html (IDEA插件创建)
来源:oschina
链接:https://my.oschina.net/u/4331678/blog/3629146