facebook

ClassPathXmlApplicationContext -Injecting Dependencies

  1. MyEclipse Archived
  2.  > 
  3. UML Development
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #233794 Reply

    jackobryan
    Member

    ClassPathXmlApplicationContext – 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 12

    The following code continues create error an:

    [/b][/code]

    #233933 Reply

    Riyad Kalla
    Member

    We 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.

    #233998 Reply

    mharley
    Member

    Be 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.

    #234000 Reply

    Riyad Kalla
    Member

    Yes 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.

Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: ClassPathXmlApplicationContext -Injecting Dependencies

You must be logged in to post in the forum log in