Results 1 to 3 of 3

Thread: Class not found - xml config file

Hybrid View

  1. #1

    Default Class not found - xml config file

    I am new to spring and I am having trouble running a program with Spring. I have created a web app and have now tried to create a basic application and the beans.xml configuration file won't load. I have it on the classpath and it is correct (I think).

    beans.xml
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns:util="http://www.springframework.org/schema/util"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
    		http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd">
    
    
    	<bean id="Console" name="ConsoleWriter"	class="glasys.lg.ConsoleWriter" >
    	</bean>
    </beans>
    TestSpring.java
    Code:
    package glasys.lg;
    
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    
    public class TestSpring
    {	
    	public static void main(String[] args)
    	{
    //line 14		ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");
    		ConsoleWriter writer = ctx.getBean("Console", ConsoleWriter.class);
    		writer.writeConsole("I Hope This Has Worked");
    	}
    }
    I have attached an image of the project explorer to show that the file is on the classpath. I have been around couple of times on this and I know that you guys are going to think me a complete noob but I am stuck. I have searched here and I could only find close problems not one the same. A possibility of library conflict was mentioned but I don't think this applies here.

    The error I keep getting is this:
    Code:
    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
    	at org.springframework.context.support.AbstractApplicationContext.<init>(AbstractApplicationContext.java:161)
    	at org.springframework.context.support.AbstractRefreshableApplicationContext.<init>(AbstractRefreshableApplicationContext.java:90)
    	at org.springframework.context.support.AbstractRefreshableConfigApplicationContext.<init>(AbstractRefreshableConfigApplicationContext.java:59)
    	at org.springframework.context.support.AbstractXmlApplicationContext.<init>(AbstractXmlApplicationContext.java:61)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:136)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    	at glasys.lg.TestSpring.main(TestSpring.java:14)
    Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
    	at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    	... 7 more
    which points at the line attempting to load the beans.xml file. Thanks
    Attached Images Attached Images

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    Read the stacktrace.

    Code:
    java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
    Which indicates you are missing a library in this case commons-logging which is the only required dependency for spring. I suggest you use maven or ant+ivy or gradle to manage your dependencies instead of trying to figure it out by yourself.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3

    Default

    Thank you. Yes I had just realised this and I thought I was using those things through springsource tool suite.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •