简体   繁体   English

Spring Boot Application:- 无法解析导入 org.springframework.boot.SpringApplication

[英]Spring Boot Application:- The import org.springframework.boot.SpringApplication cannot be resolved

I'm beginner for Spring-boot;refering some tutorials I have set up a spring boot project using the Spring Initializer.我是 Spring-boot 的初学者;参考一些教程,我使用 Spring Initializer 设置了一个 Spring Boot 项目。 I have tried to get rid of this issue by downloading dependencies again and even created new projects several times.我试图通过再次下载依赖项来解决这个问题,甚至多次创建新项目。

I'm using Eclipse neon IDE and I find error on imports import org.springframework.boot.SpringApplication.我正在使用 Eclipse neon IDE,并且在导入 import org.springframework.boot.SpringApplication 时发现错误。

I have removed repositories too many times so that jars will auto downloaded by itself when I refresh\\clean the project but problem still persists.我已经删除了太多次存储库,因此当我刷新\\清理项目时,jar 会自动下载,但问题仍然存在。

DemoApplication.java演示应用程序.java

package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

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

below is my pom.xml下面是我的 pom.xml

pom.xml pom.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 http://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.1.3.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>

<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>

<properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <start-class>com.example.demo.DemoApplication</start-class>
</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</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-autoconfigure</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </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>

Try doing this, I think this would solve尝试这样做,我认为这会解决

public static void main(final String[] aArgs)
  {
    new SpringApplicationBuilder(DemoApplication.class).run(aArgs);
  }

在 Eclipse 中:右键单击项目 -> Maven -> 更新项目应该可以工作

It was eclipse issue I found corrupted jars in repository and upgraded m2e to 1.8(solution found in Eclipse forum).这是 Eclipse 问题,我在存储库中发现损坏的 jar 并将 m2e 升级到 1.8(在 Eclipse 论坛中找到的解决方案)。 After upgrading m2e I had removed my repository and restarted eclipse.升级 m2e 后,我删除了我的存储库并重新启动了 eclipse。 Everything worked smooth 🙂一切都很顺利🙂

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring 启动应用程序在本地运行,但 Heroku 在 org.springframework.boot.SpringApplication 上抛出 ClassNotFoundException - Spring boot application runs locally but Heroku is throwing ClassNotFoundException on org.springframework.boot.SpringApplication 由于找不到org.springframework.boot.SpringApplication而导致主要方法中的Spring Boot错误 - Spring boot error in main method due to org.springframework.boot.SpringApplication not found java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication - java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication Maven - java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication Maven java:无法访问 org.springframework.boot.SpringApplication 错误的 class 文件 - java: cannot access org.springframework.boot.SpringApplication bad class file 春天:java.lang.ClassNotFoundException:找不到org.springframework.boot.SpringApplication - Spring: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication not found java.lang.ClassNotFoundException:org.springframework.boot.SpringApplication with maven-jar-plugin - java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication with maven-jar-plugin VSCode maven 项目 package org.springframework.boot.SpringApplication 不存在 - VSCode maven proj package org.springframework.boot.SpringApplication does not exist 无法解析导入org.springframework.boot.autoconfigure.web.ErrorAttributes - The import org.springframework.boot.autoconfigure.web.ErrorAttributes cannot be resolved Spring 启动 docker 线程“主”中的异常 java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication - Spring boot docker Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM