使用Maven新建SpringBoot工程

最近用IDEA插件建立Springboot项目,老是403,估计被墙了!html

 

那么这里在提供两种方法java

1.从官网下载模板,导入IDEA内web

2.使用Maven建立spring

方法一:打开 https://start.spring.io/  选择Springboot版本 写上包名 项目命  点击Generate Project  下载项目导入IDEA。(这种方法下载的工程多是SpringBoot java工程,检查SpringBootSpringBoot框架开发web项目的起步依赖是否带web   spring-boot-starter-web 如第二张图,若是不带添加便可)apache

方法二:springboot

经过Mavenmybatis

(1)简单说一下建立,大概流程就是建立一个Maven项目,在pom文件里面添加SpringBoot父级依赖,启动依赖,启动测试依赖!框架

这里我用原型建立Maven项目maven

 

 

(2)在pom.xml里面添加  SpringBoot框架的父级依赖     SpringBoot框架开发web项目的起步依赖 测试依赖spring-boot

添加好以后,在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插件建立)

相关文章
相关标签/搜索