- This topic has 3 replies, 3 voices, and was last updated 19 years, 3 months ago by Riyad Kalla.
-
AuthorPosts
-
jackobryanMemberClassPathXmlApplicationContext – fails to inject dependencies:
acutual error message:
Exception in thread “main” java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.springframework.context.support.AbstractApplicationContext.<init>(AbstractApplicationContext.java:132)
at org.springframework.context.support.AbstractApplicationContext.<init>(AbstractApplicationContext.java:164)
at org.springframework.context.support.AbstractRefreshableApplicationContext.<init>(AbstractRefreshableApplicationContext.java:66)
at org.springframework.context.support.AbstractXmlApplicationContext.<init>(AbstractXmlApplicationContext.java:49)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:77)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:65)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:56)
at com.springbook.RentABikeAssembler.main(RentABikeAssembler.java:8)Actual code:
public class RentABikeAssembler {
public static final void main(String[] args) {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(“RentABike-context.xml”);
CommandLineView clv = (CommandLineView)ctx.getBean(“commandLineView”);
clv.printAllBikes();
}
}Code is from “Spring – A Developer Notebook) by Tate & Gehtland
page 12The following code continues create error an:
[/b][/code]
Riyad KallaMemberWe have a few kinks with Spring to work out, when you added Spring capabilities it should have added commons-logging.jar for you, if it didn’t you can add it manually and add it to your classpath.
mharleyMemberBe careful. I ran into the same problem a couple weeks ago. I added the commons-logging.jar file from a standard Spring 1.2 insatllation into the classpath and ended up with a REAL messy classpath error. Basically, the Spring commons-logging.jar file includes a .properties file that references the log4j jar file. However, it also seems to have some effect on the Eclipse classpath, because even when I added log4j to the Eclipse classpath it was unable to find it!
In short, the way to avoid the problem is to make sure that you reference a “real” commons-logging.jar file – the one provided by Apache rather than the one included with Spring.
Riyad KallaMemberYes or upgrade your libraries in your proejct to Spring 1.2.3 also seems to work.
mharley, I appreciate the additional details however, these are important when trying to worka round and issue.
-
AuthorPosts