springboot环境搭建

# SpringBoot环境的配置

  • JDK 1.8.0_311
  • Maven 3.5.4
  • IDEA 2021.3.2
  • SpringBoot 2.5.0

1、JDK的配置

2、Maven的配置

变量名 变量值
MAVEN_HOME D:\apache-maven-3.5.4

path中新增%MAVEN_HOME%\bin

修改Maven的设置

地址为 D:\apache-maven-3.5.4\conf\settings.xml

1、修改本地仓库

<localRepository>D:\Maven_Repository2</localRepository

2、修改成阿里云镜像

<mirrors>
    <mirror>
      <id>aliyunmaven</id>
      <mirrorOf>central</mirrorOf>
      <name>aliyun maven</name>
      <url>https://maven.aliyun.com/repository/public </url>
    </mirror>
  </mirrors>

3、配置Maven编译的jdk版本

  <profiles>
    <profile>
      <id>jdk-1.8</id>
      <activation>
        <activeByDefault>true</activeByDefault>
        <jdk>1.8</jdk>
      </activation>
      <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
      </properties>
    </profile>
  </profiles>

4、清理Maven仓库脚本

新建一个.bat的空文件,复制下面内容

@echo off
rem create by NettQun
  
rem 这里写你的仓库路径
set REPOSITORY_PATH=D:\Maven_Repository2
rem 正在搜索...
for /f "delims=" %%i in ('dir /b /s "%REPOSITORY_PATH%\*lastUpdated*"') do (
    echo %%i
    del /s /q "%%i"
)
rem 搜索完毕
pause

3、IDEA

IDEA的安装和破解

配置IDEA

修改创建新项目的默认设置

image-20220327101138544

image-20220327101313697

创建新项目

1、直接创建maven项目

2、创建多模块项目,然后在添加maven项目

1、环境检查

检查springboot的要求

进入springboot官网

image-20220327102042821

image-20220327102128239

image-20220327102151258

检查项目jdk

image-20220327102520844

检查模板版本

image-20220327102717152

检查Maven

image-20220327102838060

检查Maven的设置

image-20220327103110048

2、HelloWorld

①继承父工程

在pom.xml中添加一下配置,继承spring-boot-starter-parent这个父工程

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.0</version>
    </parent>

②添加依赖

   <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

③创建启动类

创建一个类在其实加上@SpringBootApplication注解标识为启动类。

@SpringBootApplication
public class HelloApplication {

    public static void main(String[] args) {
        SpringApplication.run(HelloApplication.class, args);
    }
}

④定义Controller

创建Controller,主要Controller要放在启动类所在包或者其子包下。

@RestController
public class HelloController {
    @RequestMapping("/hello")
    public String hello(){
        return "hello";
    }
}

@RestController相当于@Controller+@ResponseBody

⑤运行测试

直接运行启动类的main方法即可。

打开localhost查看即可

http://localhost:8080/hello

3、打包运行(空项目创建的有坑)

​ 我们可以把springboot的项目打成jar包直接去运行。

①添加maven插件

    <build>
        <plugins>
            <!--springboot打包插件-->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

②maven打包

image-20210528143119257

打包结果

image-20220327105705813

③运行jar包

在jar包所在目录执行命令

java -jar jar包名称

即可运行。

遇到了下面的问题

image-20220327111031155

卡在这里了是因为开启了快速编辑模式

image-20220327111147720

可以按ctrl+c让他继续输出(未能解决问题)

4、快速构建

使用Spring Initializr创建

BUG

1、spring-boot-maven-plugin报错

<version>2.3.4.RELEASE</version>

加上版本,然后重启就ok

posted @   yilan0916  阅读(447)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示