1 Star 0 Fork 0

qinpmc/springboot_demos

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
contribute
Sync branch
qinpei- qinpei add mvc demo c77cc84 2 years ago
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README

IDEA 中使用 Springboot

1 IDEA创建springboot项目

1.1 创建过程

  • 1 菜单中选择File –> New –> Project,选择Spring Initializr,
  • 2 根据提示,输入 Group、Artifact、Type(一般选Maven),本机jdk为11,所以 Project SDK 和Java 均选择 11
  • 3 点击next,在 springboot中选择2.7.17 ,选择Dependencies,此处选Web-Spring Web,然后finish即可
  • 4 配置maven, File-> Settings,搜索maven,在 build tools 下面找到 Maven,设置Maven home path ,配置完成后, 可以点开 maven然后 更新

项目的pom.xml主要有四个部分:

  • 项目元数据:groupId、artifactId、version、name、description等
  • parent:Spring Boot 父级依赖, spring-boot-starter-parent 是一个特殊 Starter,它提供了有用的 Maven 默认配置。此外它还提供了依赖管理功能,您可以忽略这些依赖的版本(version)标签。
  • dependencies:项目具体依赖,这里包含了 spring-boot-starter-web 用于实现HTTP接口, spring-boot-starter-test 用于编写单元测试的依赖包。
  • build:构建配置部分,默认使用了 spring-boot-maven-plugin (Spring Boot Maven插件),配合 spring-boot-starter-parent 就可以把Spring Boot 应用打包成 JAR 来直接运行。

<?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 https://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.7.17</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>springboot_demos</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>springboot_demos</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>11</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

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

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

1.2 创建常见问题

1.2.1 springboot 项目中pom.xml的 parent中的 version 报红色 (鼠标划上红色内容提示 Project ‘org.springframework.boot:spring-boot-starter-parent’ not found)

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.17</version> <!-- 这里红色 -->
        <relativePath/> <!-- lookup parent from repository -->
</parent>

选择 File ------>Invalidate Caches / Restart (点击进行重启项目) 解决

1.2.2 springboot 项目中pom.xml的 spring-boot-maven-plugin报红色(鼠标划上红色内容提示 Plugin ‘org.springframework.boot:spring-boot-maven-plugin:’ not found)

解决方案同 1.2.1 也可以添加具体的版本号(使用 File ------>Invalidate Caches / Restart 解决了,添加版本号 未具体尝试)

1.2.3 类文件具有错误的版本 62.0, 应为 52.0

创建项目时使用了默认的 spring boot 3.1.4,即使勾选了使用jdk 11,项目初始后发现pom.xml中仍然为:
<java.version>17</java.version> 即使收到修改为 11 版本(本地的jdk版本),仍然报错:
类文件具有错误的版本 62.0, 应为 52.0 ,查询后得知spring boot 3.x 需要使用jdk17版本。 解决: 创建项目时,使用 spring boot 2.7.16

Empty file

Releases

No release

Contributors

All

Language(Optional)

Activities

can not load any more
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/qinpmc/springboot_demos.git
git@gitee.com:qinpmc/springboot_demos.git
qinpmc
springboot_demos
springboot_demos
master

Search