編輯:當我從SPRING DEPENDENCY @ POM.XML刪除PROVIDED它突然工作,有人可以告訴我爲什麼它的工作,而不是?不能運行春天你好世界繼續得到NoClassDefFoundError
嗨,大家好我不斷收到
Caused by: java.lang.NoClassDefFoundError: org/springframework/beans/factory/support/BeanDefinitionRegistry
每當我試圖執行
mvn exec:java -Dexec.mainClass="org.carlos.spring.FirstSpringHelloWorld"
我的代碼
的代碼如下
package org.carlos.spring;
import org.springframework.beans.factory.support.BeanDefinitionReader;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.PropertiesBeanDefinitionReader;
import org.springframework.core.io.ClassPathResource;
import org.carlos.decoupled.MessageSource;
import org.carlos.decoupled.MessageDestination;
public class FirstSpringHelloWorld {
public static void main(String[] args) {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
BeanDefinitionReader reader = new PropertiesBeanDefinitionReader(bf);
reader.loadBeanDefinitions(new ClassPathResource("/META-INF/spring/helloworld-context.properties"));
MessageSource source = (MessageSource) bf.getBean("source");
MessageDestination destination = (MessageDestination) bf.getBean("destination");
destination.write(source.getMessage());
}
}
package org.carlos.decoupled;
public interface MessageSource {
String getMessage();
}
package org.carlos.decoupled;
public interface MessageDestination {
void write(String message);
}
,這是我的POM.XML
個<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.carlos.hello</groupId>
<artifactId>hello</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>hello Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>2.5.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>2.5.5</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>hello</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
</project>
hello-world-context.properties:
source.(class)=org.carlos.decoupled.SimpleMessageSource
destination.(class)=org.carlos.decoupled.StdoutMessageDestination
可有人請告訴我如何解決這個問題?我很有趣:(
嘗試在其中創建一個罐子,它將使所有的lib在運行時也可以使用 – 2011-05-10 12:23:27
使用mvn instal assembly:assembly?我很新MVN請詳細說明ty! – Jimmy 2011-05-10 12:32:22