我在运行mvn install时收到包org.springframework.stereotype错误。即使在.m2文件夹中也有该软件包。
通过这行代码向我显示错误:
import org.springframework.stereotype.Service;
Run Code Online (Sandbox Code Playgroud)
依赖项是:
<springVersion>4.1.1.RELEASE</springVersion>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${springVersion}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${springVersion}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${springVersion}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${springVersion}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${springVersion}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${springVersion}</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
有什么我想念的吗?
更新
这是我得到的全部错误:
ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.2:compile (default-compile) on project mynewProject: Compilation failure: Compilation failure:
[ERROR] /C:/mynewProject/src/main/java/com/web/server/domain/service/WebServiceImpl.java:[17,38] package org.springframework.stereotype does not exist
[ERROR] /C:/mynewProject/src/main/java/com/web/server/domain/service/WebServiceImpl.java:[25,2] cannot find symbol
Run Code Online (Sandbox Code Playgroud)
小智 7
在Java 8和spring 4.x上运行时,在独立的Java程序上遇到类似的问题。
由于某种原因,我在项目引用的Jars中看不到spring-context。它应该由maven自动引用,但是我没有看到这种情况。
解决方案:我在pom.xml中手动添加了spring-context依赖项,并且我的错误已修复。
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.2.5.RELEASE</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我需要将范围标记更改为“编译”而不是“运行时”,错误消失了。
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
<scope>compile</scope>
Run Code Online (Sandbox Code Playgroud)
小智 4
所有依赖项都应该在
<dependencies>
...
</dependencies>
Run Code Online (Sandbox Code Playgroud)
...或者你的代码将继续抛出该错误。
| 归档时间: |
|
| 查看次数: |
19406 次 |
| 最近记录: |