web-dev-qa-db-ja.com

パッケージorg.springframework.bootは存在しません

私は自分のマシンで小さな基本的なSpringブートプログラムを実行しようとしていますが、clean compile(spring-boot:runを試す前であっても)Mavenで次のエラーが表示されます。

[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /C:/Users/hbenayed/Eclipse-workspace/SpringBootPoc/src/main/Java/com/benayed/spboot/poc/SpringBootPoc/SpringBootPocApplication.Java:[3,32] package org.springframework.boot does not exist
[ERROR] /C:/Users/hbenayed/Eclipse-workspace/SpringBootPoc/src/main/Java/com/benayed/spboot/poc/SpringBootPoc/SpringBootPocApplication.Java:[4,46] package org.springframework.boot.autoconfigure does not exist
[ERROR] /C:/Users/hbenayed/Eclipse-workspace/SpringBootPoc/src/main/Java/com/benayed/spboot/poc/SpringBootPoc/SpringBootPocApplication.Java:[6,2] cannot find symbol
  symbol: class SpringBootApplication
[ERROR] /C:/Users/hbenayed/Eclipse-workspace/SpringBootPoc/src/main/Java/com/benayed/spboot/poc/SpringBootPoc/SpringBootPocApplication.Java:[10,17] cannot find symbol
  symbol:   variable SpringApplication
  location: class com.benayed.spboot.poc.SpringBootPoc.SpringBootPocApplication
[INFO] 4 errors 
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 14.807 s
[INFO] Finished at: 2018-02-18T03:28:24+01:00
[INFO] Final Memory: 19M/167M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.Apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project SpringBootPoc: Compilation failure: Compilation failure:
[ERROR] /C:/Users/hbenayed/Eclipse-workspace/SpringBootPoc/src/main/Java/com/benayed/spboot/poc/SpringBootPoc/SpringBootPocApplication.Java:[3,32] package org.springframework.boot does not exist
[ERROR] /C:/Users/hbenayed/Eclipse-workspace/SpringBootPoc/src/main/Java/com/benayed/spboot/poc/SpringBootPoc/SpringBootPocApplication.Java:[4,46] package org.springframework.boot.autoconfigure does not exist
[ERROR] /C:/Users/hbenayed/Eclipse-workspace/SpringBootPoc/src/main/Java/com/benayed/spboot/poc/SpringBootPoc/SpringBootPocApplication.Java:[6,2] cannot find symbol
[ERROR] symbol: class SpringBootApplication
[ERROR] /C:/Users/hbenayed/Eclipse-workspace/SpringBootPoc/src/main/Java/com/benayed/spboot/poc/SpringBootPoc/SpringBootPocApplication.Java:[10,17] cannot find symbol
[ERROR] symbol:   variable SpringApplication
[ERROR] location: class com.benayed.spboot.poc.SpringBootPoc.SpringBootPocApplication
[ERROR] -> [Help 1]
org.Apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.Apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project SpringBootPoc: Compilation failure
    at org.Apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.Java:212)
    at org.Apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.Java:153)
    at org.Apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.Java:145)
    at org.Apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.Java:116)
    at org.Apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.Java:80)
    at org.Apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.Java:51)
    at org.Apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.Java:128)
    at org.Apache.maven.DefaultMaven.doExecute(DefaultMaven.Java:307)
    at org.Apache.maven.DefaultMaven.doExecute(DefaultMaven.Java:193)
    at org.Apache.maven.DefaultMaven.execute(DefaultMaven.Java:106)
    at org.Apache.maven.cli.MavenCli.execute(MavenCli.Java:863)
    at org.Apache.maven.cli.MavenCli.doMain(MavenCli.Java:288)
    at org.Apache.maven.cli.MavenCli.main(MavenCli.Java:199)
    at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:62)
    at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43)
    at Java.lang.reflect.Method.invoke(Method.Java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.Java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.Java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.Java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.Java:356)
Caused by: org.Apache.maven.plugin.compiler.CompilationFailureException: Compilation failure
    at org.Apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.Java:858)
    at org.Apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.Java:129)
    at org.Apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.Java:134)
    at org.Apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.Java:207)
    ... 20 more
[ERROR] 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.Apache.org/confluence/display/MAVEN/MojoFailureException

これが私の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>

    <groupId>com.benayed.spboot.poc</groupId>
    <artifactId>SpringBootPoc</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>SpringBootPoc</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.10.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <Java.version>1.8</Java.version>
    </properties>

    <dependencies>
        <!-- <dependency> -->
        <!-- <groupId>org.springframework.boot</groupId> -->
        <!-- <artifactId>spring-boot-starter-data-jpa</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>

そしてここに私のJava Class:

package com.benayed.spboot.poc.SpringBootPoc;

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

@SpringBootApplication
public class SpringBootPocApplication {

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

}

.m2リポジトリを削除したり、異なるタグ(バージョン、フォークなど)をspring-boot-maven-pluginプラグインは、問題を引き起こしている部分であると確信しています。

助言がありますか ?

7
FrankelStein

spring-boot-starter-data-jpaをコメントアウトしているため、コンパイルの依存関係は0個あり、テストコンパイルの依存関係のみが定義されています。 Springスターターは、他の依存関係(他のスターターを含む)をプルして、コンパイル時に必要なすべてを作成します。 spring-boot-starter-data-jpa依存関係のコメントを解除するか、実際に必要な依存関係を再評価します。

5
Darren Forsythe

この依存関係を追加する必要があります

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

その後、動作します。

7
Do Nhu Vy

依存関係管理の外部に以下のセクションを追加し、プロジェクトの更新を行います。そして、Mavenのクリーンインストール。

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.10.RELEASE</version>
    </parent>

そして、以下の依存関係。

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

修正されない場合(起こりそうにない)、言及された他の依存関係を追加します here

0
kemparaj565

1)プロジェクトを閉じる2)自動インポートをオンにしてプロジェクトを再度インポートする

これは私のために働いた。たぶんあなたのためにも働きます。

0
Vimukthi Sineth