Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot access org.springframework.core.env.EnvironmentCapable

Tags:

java

spring

maven

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");

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

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

Basic Project Configuration:

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

Any idea is welcome!

like image 393
Ellison Alves Avatar asked Aug 25 '14 14:08

Ellison Alves


2 Answers

Finally, I've solved it! :)

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>

Note that:

  • If you're having this problem, make sure that you're using a spring version 3.1 or higher.
  • Remember that ${spring.version}, in my case, is 3.1.1.RELEASE.

I hope that it helps more people.

like image 50
Ellison Alves Avatar answered Nov 11 '22 16:11

Ellison Alves


I was facing the exact same issue, maven complains from org.springframework.core.env.EnvironmentCapable, even with the file there, inside the jar: C:\Users\fabio\.m2\repository\org\springframework\spring-core\4.3.12.RELEASE\spring-core-4.3.12.RELEASE.jar.

The solution im my case was delete the .m2 folder, so maven downloaded all the jars again. Maybe it was some currupted file.

I hope it helps some one!

like image 22
Fábio Magagnin Avatar answered Nov 11 '22 14:11

Fábio Magagnin