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
TestSpring.javaCode:<?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>
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.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"); } }
The error I keep getting is this:
which points at the line attempting to load the beans.xml file. ThanksCode: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


Reply With Quote