Intellij IDEA启动第一个SpringBoot项目

1. 下载maven

maven是java项目开发的一个管理工具,类似Linux中的MakeFile,在创建SpringBoot时需要用Maven自动下载依赖,如果你没有maven,那么会一片红。
安装和配置maven的教程
新建项目时自动配置maven

安装完后可以在工程项目下的pom.xml中加入如下代码,尝试下载jar包:

    <dependencies>
        <dependency>
            <groupId>net.schmizz</groupId>
            <artifactId>sshj</artifactId>
            <version>0.10.0</version>
        </dependency>
        <dependency>
            <groupId>com.redislabs</groupId>
            <artifactId>spark-redis</artifactId>
            <version>2.4.0</version>
        </dependency>
    </dependencies>

导入代码后记得在右侧的maven边栏点击刷新或是下载
安装完后为了加快下载的速度你可能还需要做出如下配置:

  1. setting->maven->importingVM选项中输入如下代码-DarchetypeCatalog=internal -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true
  2. setting->maven中把配置文件和Maven的home path改为本地的
    如果你想要用maven导入更多的jar包可以到中央仓库中寻找
  3. 如果发现运行项目报错则可以尝试在File ->Settings ->Build, Execution, Deployment ->Compiler 中的build process VM options栏目加入-Djdk.lang.Process.launchMechanism=vfork

2. 使用Intellij IDEA自带的模组新建SpringBoot项目

只有企业版的Intellij IDEA才能使用SpringBoot
SpringBoot教程极致版
如果创建时出现下载失败,你可以尝试把源换成https://start.aliyun.com/
如果在运行时出现了org.junit.jupiter.api不存在则在pom.xml添加如下的依赖

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>RELEASE</version>
            <scope>test</scope>
        </dependency>

或是采用另一位博主的方法

运行时报错的解决方法

如果按照上面的参考资料无法运行,那么大概率是JDK版本的问题,只要把JDK换成JDK8/JDK1.8就可以成功运行了

  • 更换JDK的方法
    1. 点击Intellij IDEA的File->Project Structure-> Project->SDK->选择下载一个JDK1.8/JDK8
    2. 下载完后把JDK文件中的bin文件夹加入到环境变量中
      在这里插入图片描述
    3. 按照网上的相关发方法重新配置项目的JDK选项
    4. 也可以直接用Intellij IDEA新建一个SpringBoot项目(版本选择JDK1.8,Java8),然后把源代码复制进去就好了。我个人是比较推荐这种方法,因为快和简单

3. 成功运行截图

在这里插入图片描述
在这里插入图片描述
gitee仓库:https://gitee.com/liang-jiajun2/hello-spring-boot.git

猜你喜欢

转载自blog.csdn.net/qq_33880925/article/details/127972863