首页 > 解决方案 > 包 org.springframework.boot 不存在但对我不起作用

问题描述

I am trying to run the spring boot project in IntelliJ, I am facing issues when compiling the code. Detailed explanation below.

**bold**Error below **bold**

` javac StudentApplication.java

StudentApplication.java:6:错误:包 org.springframework.boot 不存在导入 org.springframework.boot.SpringApplication;^ StudentApplication.java:7:错误:包 org.springframework.boot.autoconfigure 不存在导入 org.springframework.boot.autoconfigure.SpringBootApplication;^ StudentApplication.java:9:错误:找不到符号@SpringBootApplication ^ 符号:类 SpringBootApplication StudentApplication.java:14:错误:找不到符号 SpringApplication.run(^ 符号:变量 SpringApplication 位置:类 StudentApplication 4 错误`

Below is my StudentApplication.java '我在 SpringApplication.run 中遇到错误'

//import org.springframework.context.ApplicationContext;


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class StudentApplication {

  public static void main(String[] args) {
    //ApplicationContext ctx =
        SpringApplication.run(
        StudentApplication.class, args);
    //System.out.println(ctx);
  }
}

Below is my porm.xml '与列表'''

<?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.4.4</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>info.inet</groupId>
    <artifactId>coursestudent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>coursestudent</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-security</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-rest</artifactId>
        </dependency>

        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.dataformat</groupId>
            <artifactId>jackson-dataformat-xml</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>

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

        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-rest-hal-browser</artifactId>
            <version> 3.3.6.RELEASE </version>
        </dependency>

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

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>4.2.5.RELEASE</version>
        </dependency>

    </dependencies>

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

</project>

我无法解决它。即使在 porm.xml 文件中添加了依赖项。任何人都可以帮助我。如果需要,我会推送 git 以查看完整代码。但请不要不必要地关闭它。

标签: javaspringspring-bootmaven

解决方案


你的远程 Maven 仓库更新了吗?查看

Settings -> Build, Execution, Deployment -> Build tools -> Maven -> Repositories

推荐阅读