Spring, og xml, classNotFount
Jeg prøver at lave et lille spring eksempel til mig selv, for at se hvordan det virker.Men jeg få desvære denne fejl:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.springframework.util.ClassUtils.<clinit>(ClassUtils.java:73)
at org.springframework.core.io.DefaultResourceLoader.<init>(DefaultResourceLoader.java:52)
at org.springframework.context.support.AbstractApplicationContext.<init>(AbstractApplicationContext.java:198)
at org.springframework.context.support.AbstractRefreshableApplicationContext.<init>(AbstractRefreshableApplicationContext.java:80)
at org.springframework.context.support.AbstractXmlApplicationContext.<init>(AbstractXmlApplicationContext.java:58)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:119)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:66)
at CommandLineView.main(CommandLineView.java:24)
Hvordan kommer jeg denne fejl til lives ?
Jeg køre med Eclipse Enterprice, og har laves et web projekt. Dog køre jeg bare med en standart main metode.
Bare for at se om det hele bliver injected som det skal, af spring.
Mening er at det skal udbygges med et web, og hibernate :) Men endtil nu, hvordan får jeg rettes op på denne fejl.
kode Structur:
F:\eclipse workspace\BikeWithSpringEksampel\.classpath
F:\eclipse workspace\BikeWithSpringEksampel\.project
F:\eclipse workspace\BikeWithSpringEksampel\.settings
F:\eclipse workspace\BikeWithSpringEksampel\build
F:\eclipse workspace\BikeWithSpringEksampel\dir.list.txt
F:\eclipse workspace\BikeWithSpringEksampel\lib
F:\eclipse workspace\BikeWithSpringEksampel\src
F:\eclipse workspace\BikeWithSpringEksampel\WebContent
F:\eclipse workspace\BikeWithSpringEksampel\.settings\org.eclipse.jdt.core.prefs
F:\eclipse workspace\BikeWithSpringEksampel\.settings\org.eclipse.jst.common.project.facet.core.prefs
F:\eclipse workspace\BikeWithSpringEksampel\.settings\org.eclipse.wst.common.component
F:\eclipse workspace\BikeWithSpringEksampel\.settings\org.eclipse.wst.common.project.facet.core.xml
F:\eclipse workspace\BikeWithSpringEksampel\build\classes
F:\eclipse workspace\BikeWithSpringEksampel\build\classes\Bike.class
F:\eclipse workspace\BikeWithSpringEksampel\build\classes\CommandLineView.class
F:\eclipse workspace\BikeWithSpringEksampel\build\classes\IRentABike.class
F:\eclipse workspace\BikeWithSpringEksampel\build\classes\MyServlet.class
F:\eclipse workspace\BikeWithSpringEksampel\build\classes\RentABike.class
F:\eclipse workspace\BikeWithSpringEksampel\lib\javax.servlet.jar
F:\eclipse workspace\BikeWithSpringEksampel\lib\spring-beans.jar
F:\eclipse workspace\BikeWithSpringEksampel\lib\spring-context.jar
F:\eclipse workspace\BikeWithSpringEksampel\lib\spring-core.jar
F:\eclipse workspace\BikeWithSpringEksampel\lib\spring-sources.jar
F:\eclipse workspace\BikeWithSpringEksampel\src\Bike.java
F:\eclipse workspace\BikeWithSpringEksampel\src\CommandLineView.java
F:\eclipse workspace\BikeWithSpringEksampel\src\RentABike.java
F:\eclipse workspace\BikeWithSpringEksampel\WebContent\index.jsp
F:\eclipse workspace\BikeWithSpringEksampel\WebContent\META-INF
F:\eclipse workspace\BikeWithSpringEksampel\WebContent\WEB-INF
F:\eclipse workspace\BikeWithSpringEksampel\WebContent\META-INF\MANIFEST.MF
F:\eclipse workspace\BikeWithSpringEksampel\WebContent\WEB-INF\application-context.xml
F:\eclipse workspace\BikeWithSpringEksampel\WebContent\WEB-INF\classes
F:\eclipse workspace\BikeWithSpringEksampel\WebContent\WEB-INF\lib
F:\eclipse workspace\BikeWithSpringEksampel\WebContent\WEB-INF\web.xml
// bike //
public class Bike {
private String model;
private int price;
public Bike(String model, int price) {
this.model = model;
this.price = price;
}
public String toString() {
return "Bike : model: " + model + " \n: price: " + price;
}
public String getModel() {
return model;
}
}
// RentABike //
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class RentABike {
private String storeName;
private List bikes;
public RentABike() {
initBike();
}
private void initBike() {
bikes = new ArrayList();
bikes.add(new Bike("model1", 200));
bikes.add(new Bike("model2", 400));
bikes.add(new Bike("model3", 600));
}
public List getBikes() {
return bikes;
}
public Bike getBike(String model) {
Iterator iter = bikes.iterator();
while(iter.hasNext()) {
Bike bike = (Bike) iter.next();
if (bike.getModel().equals(model))
return bike;
}
return null;
}
}
// CommandLineView //
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
public class CommandLineView {
private RentABike facade;// = new RentABike();
public void print() {
java.util.Iterator iter = facade.getBikes().iterator();
while (iter.hasNext()) {
Bike bike = (Bike) iter.next();
System.out.println(bike.toString());
}
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("RentAB ike-context.xml");
//CommandLineView clv = new CommandLineView();
CommandLineView clv = (CommandLineView) ctx.getBean("CommandLineView");
clv.print();
}
}
// application.context.xml //
<?xml version="1.0"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="commandLineView" class="CommandLineView">
<property name="rentaBike"><ref bean="rentaBike"/></property>
</bean>
</beans>
Jeg håber dette er nok information, ellers spørger i bare.
Jeg kan også sende det til jer :)
/// dennis
