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

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存在!:/

基本项目配置:

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

欢迎任何想法!

Ell*_*ves 6

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

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

注意:

  • 如果您遇到此问题,请确保使用的是弹簧版本3.1或更高版本.
  • 请记住,在我的情况下,$ {spring.version}是3.1.1.RELEASE.

我希望它能帮助更多人.


Fáb*_*nin 5

我面临着完全相同的问题,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。也许这是一些损坏的文件。

我希望它对某人有所帮助!

  • 我只是删除了“~/.m2/repository/org/springframework”,而不是整个“~/.m2”目录(我真的不想再次下载整个互联网......)。我猜我可以删除 `~/.m2/repository/org/springframework/spring-core` 目录。 (4认同)
  • 我可以确认 `rm -rf ~/.m2/repository/org/springframework/spring-core` 解决了问题 (4认同)