Java 包 org.springframework.boot 不存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48847951/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
package org.springframework.boot does not exist
提问by FrankelStein
I am trying to run a Small basic Spring boot program on my machine and I when I run clean compile
(even before trying spring-boot:run) on maven I get the following Error :
我正在尝试在我的机器上运行一个小型基本 Spring 启动程序,当我clean compile
在 maven 上运行(甚至在尝试 spring-boot:run 之前)时,我收到以下错误:
[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
Here is my 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>
<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>
And here is my java Class :
这是我的 java 类:
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);
}
}
I tried many solutions I could find on internet, such as deleting the .m2 repository, adding different tags (version, fork,...) to the spring-boot-maven-plugin
plugin which, I'm pretty sure, is the part causing the problem
我尝试了许多可以在互联网上找到的解决方案,例如删除 .m2 存储库,向spring-boot-maven-plugin
插件添加不同的标签(版本、分叉等),我很确定这是导致问题的部分
Any suggestions ?
有什么建议 ?
采纳答案by Darren Forsythe
You have 0 compile dependencies, only test-compile dependencies defined, because you've commented out spring-boot-starter-data-jpa
. Spring starter's pull other dependencies in (including other starters) to create everything needed at compile time. Un-comment the spring-boot-starter-data-jpa
dependency, and/or re-evaulate what dependencies you actually want.
您有 0 个编译依赖项,仅定义了测试编译依赖项,因为您已将spring-boot-starter-data-jpa
. Spring starter 拉入其他依赖项(包括其他 starter)以创建编译时所需的一切。spring-boot-starter-data-jpa
取消对依赖项的注释,和/或重新评估您实际需要的依赖项。
回答by Do Nhu Vy
You need add this dependency
您需要添加此依赖项
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
then it will work.
然后它会起作用。
回答by kemparaj565
Add the below section outside dependency management and do an update of project. And then the clean install of maven.
在依赖管理之外添加以下部分并更新项目。然后是maven的全新安装。
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
</parent>
And the below dependency.
以及以下依赖项。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
If does not fix (Not Likely to happen) then add the other dependencies mentioned here
如果没有修复(不太可能发生),则添加此处提到的其他依赖项
回答by Vimukthi Sineth
1) Close the project 2) Import the project again with auto-import checked
1) 关闭项目 2) 再次导入项目并选中自动导入
This worked for me. Maybe works for you too.
这对我有用。也许也适合你。