【问题标题】:package org.springframework.boot does not exist but not working for me包 org.springframework.boot 不存在但对我不起作用
【发布时间】:2021-07-06 18:26:34
【问题描述】:

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 以查看完整代码。但请不要不必要地关闭它。`

【问题讨论】:

    标签: java spring spring-boot maven


    【解决方案1】:

    你的远程 maven 仓库更新了吗? 检查

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

    【讨论】:

    • 我按照您的指示浏览了 Maven 存储库。是的,有一个错误。能否请您给我建议如何解决它
    • @krishna 能否请您具体说明问题所在?
    • URL,类型,更新 ===> repo.maven.apache.org/maven2,远程,错误。但在下一行,一切都很好。 ../.m2/repository,本地,2021-01-17。对不起,我无法发布图片
    • 这是根本原因 - 如果更新失败,您必须更新远程仓库才能使用最新的 Spring Boot 版本,然后检查您与远程仓库的连接(可能是防火墙阻止了它等等)
    • java.lang.RuntimeException:java.io.IOException:Transfer for nexus-maven-repository-index.gz failed ====> 这是 Maven 存储库中显示的错误。你能帮我么。我检查了互联网连接。它工作正常。
    猜你喜欢
    • 2018-07-28
    • 1970-01-01
    • 1970-01-01
    • 2023-02-14
    • 1970-01-01
    • 2019-05-21
    • 1970-01-01
    • 2019-01-11
    • 2019-11-08
    相关资源
    最近更新 更多