Indirectly referenced from required .class files

2019-04-28 05:51发布

I'm getting below error in STS:

The type org.springframework.core.env.EnvironmentCapable cannot be resolved. It is indirectly referenced from required .class files

4条回答
贼婆χ
2楼-- · 2019-04-28 06:11

From command line, run "mvn clean install", you'll see project failed and you'll see artifacts in the logs that cause such a problem. After that, remove artifacts from .m2/repository, then maven update from eclipse.

查看更多
疯言疯语
3楼-- · 2019-04-28 06:19

To avoid jar collision, make sure you declare your dependency versions under the properties tag in the aggregate pom.xml, and use the property name as a placeholder throughout the project. For example 4.2.5.RELEASE in the parent pom, and then in the child modules just use ${spring.version} instead of 4.2.5.RELEASE. This way you can avoid having two different versions of the same library on the classpath.

Also it is recommended to be consistent with the version of spring dependencies. Use the same version for spring-core, spring-web etc.

If you are using maven, then you can use the maven enforcer plugin to ensure dependency convergence, and avoid further issues with transitive dependencies.

查看更多
可以哭但决不认输i
4楼-- · 2019-04-28 06:20

This sounds like a transitive dependency issue. What this means is that your code relies on a jar or library to do something - evidently, you depend on Spring framework code. Well, all that Spring code also depends on libraries and jars.

Most likely, you need to add the corerctly versioned org.springframework.core jar to your classpath so that the EnvironmentCapable class can be found when your IDE attempts to build your project.

This might also be a jar collision issue as well, although that sounds less likely. When an application experiences jar collision (also known as "dll hell"), the compiler is finding multiple jars and classes with the same fully-qualified name. For example, let's say you added Spring to your classpath, along with the entire Tomcat server library. Well, those two jars may contain the same exact named classes, maybe the same version, maybe different versions. But either way, when the compiler looks for that EnvironmentCapable class, it finds two (in this contrived example) - one in the Spring jar and one in the Tomcat jar. Well, it doesn't know which one to choose, and so it throws a ClassDefNotFoundException, which would/could manifest itself as the error you experienced.

查看更多
放荡不羁爱自由
5楼-- · 2019-04-28 06:35

I faced same error while i work with spring security on spring-security-config.i jsut deleted that jar in maven repo and gave maven->update Project in eclipse. it is resolved.Please try it once.

查看更多
登录 后发表回答