Ell*_*ves 11 java spring maven
我正在尝试使用它在Web应用程序中获取一个spring bean:
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
AClass aClass = (aClass) wac.getBean("aClass");
Run Code Online (Sandbox Code Playgroud)
并且,当我使用maven运行compile/test/package时,会发生错误:
cannot access org.springframework.core.env.EnvironmentCapable
[ERROR] class file for org.springframework.core.env.EnvironmentCapable not found
Run Code Online (Sandbox Code Playgroud)
最奇怪的是org.springframework.core.env.EnvironmentCapable存在!:/
基本项目配置:
欢迎任何想法!
最后,我已经解决了!:)
在pom.xml文件中,我必须定义spring的依赖项的范围以进行编译.(是的,我知道这是依赖的默认范围,但由于某种原因,maven无法胜任这项工作).看到我的pom.xml片段让问题消失了:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
<scope>compile</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
注意:
我希望它能帮助更多人.
我面临着完全相同的问题,maven 抱怨org.springframework.core.env.EnvironmentCapable,即使文件存在于 jar: 内C:\Users\fabio\.m2\repository\org\springframework\spring-core\4.3.12.RELEASE\spring-core-4.3.12.RELEASE.jar。
我的解决方案是删除该.m2文件夹,因此 Maven 再次下载了所有 jar。也许这是一些损坏的文件。
我希望它对某人有所帮助!
| 归档时间: |
|
| 查看次数: |
30369 次 |
| 最近记录: |