无法访问org.springframework.core.env.EnvironmentCapable [英] cannot access org.springframework.core.env.EnvironmentCapable

查看:1422
本文介绍了无法访问org.springframework.core.env.EnvironmentCapable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用它在Web应用程序中获取一个spring bean:

I'm trying to get a spring bean in a web application using it:

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

而且,当我使用maven运行compile / test / package时,会发生错误:

And, when I run compile/test/package with maven, an error occurs:

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

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

The most strange is that org.springframework.core.env.EnvironmentCapable exists! :/

基本项目配置:


  • Spring 3.1.1.RELEASE(类路径中没有其他spring版本。)

  • Maven 3

  • JSF 2.1

  • Servlet API 2.5

  • Spring 3.1.1.RELEASE (There isn't other spring version in classpath)
  • Maven 3
  • JSF 2.1
  • Servlet API 2.5

欢迎任何想法!

推荐答案

最后,我已经解决了! :)

Finally, I've solved it! :)

在pom.xml文件中,我必须定义spring的依赖项的范围才能编译。 (是的,我知道这是依赖的默认范围,但由于某些原因,maven无法胜任这项工作)。查看我的pom.xml中使问题消失的部分:

In the pom.xml file, I had to define the scope of spring's dependencies to compile. (Yes, I know that is the default scope of dependencies but for some reason maven was not capable of the job). See a piece of my pom.xml that made the problem disapear:

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

我希望它能帮助更多人。

I hope that it helps more people.

这篇关于无法访问org.springframework.core.env.EnvironmentCapable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆