gpt4 book ai didi

java - 无法访问 org.springframework.core.env.EnvironmentCapable

转载 作者:IT老高 更新时间:2023-10-28 13:50:13 27 4
gpt4 key购买 nike

我正在尝试在使用它的 Web 应用程序中获取 Spring bean:

WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
AClass aClass = (aClass) wac.getBean("aClass");

而且,当我用 maven 运行 compile/test/package 时,会出现错误:

cannot access org.springframework.core.env.EnvironmentCapable
[ERROR] class file for org.springframework.core.env.EnvironmentCapable not found

最奇怪的是 org.springframework.core.env.EnvironmentCapable 存在! :/

基本项目配置:

  • Spring 3.1.1.RELEASE(类路径中没有其他的spring版本)
  • Maven 3
  • JSF 2.1
  • Servlet API 2.5

欢迎提出任何想法!

最佳答案

终于解决了! :)

在 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>

注意:

  • 如果您遇到此问题,请确保您使用的是 Spring 3.1 或更高版本。
  • 请记住,就我而言,${spring.version} 是 3.1.1.RELEASE。

希望能帮助到更多的人。

关于java - 无法访问 org.springframework.core.env.EnvironmentCapable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25488194/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com