我正在尝试使用它在 Web 应用程序中获取 spring bean:
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
AClass aClass = (aClass) wac.getBean("aClass");
并且,当我使用 Maven 运行编译/测试/打包时,会发生错误:
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
- 服务程序 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>
注意:
- 如果您遇到此问题,请确保您使用的是弹簧
3.1 或更高版本。
- 请记住,在我的例子中,${spring.version} 是 3.1.1.RELEASE。
我希望它能帮助更多的人。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)