我想学习春天,而我下面这个教程:
https://www.javatpoint.com/spring-tutorial。
下面是我做了什么:
我创建了一个目录springtutorial
并把这两个文件吧:
Student.java
package com.javatpoint;
public class Student{
private String name;
public String getName(){
return name;
}
public void displayInfo(){
System.out.println("Hello:" + name);
}
}
Test.java
:
package com.javatpoint;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
public class Test {
public static void main(String[] args){
Resource resource = new ClassPathResource("applicationContext.xml");
BeanFactory factory = new XmlBeanFactory(resource);
Student student = (Student) factory.getBean("studentbean");
student.displayInfo();
}
}
另外,我已经创建了一个XML文件applicationContext.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="https://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="studentbean" class="com.javatpoint.Student">
<propertyname="name" value="Vimal Jaiswal"></property>
</bean>
</beans>
最后,我已经下载了这些弹簧核心文件:https://www.javatpoint.com/src/sp/spcorejars.zip
我已经把一切都只是在同一个文件夹中的.jar文件。该.jar文件被放置在一个子文件夹:
~/springtutorial$ ls
applicationContext.xml spcorejars Student.java Test.java
~/springtutorial$ ls spcorejars/
com.springsource.org.apache.commons.logging-1.1.1.jar org.springframework.beans-3.0.1.RELEASE-A.jar
com.springsource.org.apache.log4j-1.2.15.jar org.springframework.context-3.0.1.RELEASE-A.jar
jmxtools-1.2.1.jar org.springframework.core-3.0.1.RELEASE-A.jar
org.springframework.asm-3.0.1.RELEASE-A.jar org.springframework.expression-3.0.1.RELEASE-A.jar
编译Student.java
正常工作:
~/springtutorial$ javac -d . Student.java
和SOM修修补补后,我设法编译Test.java
(在单独的子文件夹.jar文件):
~/springtutorial$ javac -cp ".:spcorejars/*" -d . Test.java
但我不能运行测试文件:
~/springtutorial$ java com.javatpoint.Test
Error: Unable to initialize main class com.javatpoint.Test
Caused by: java.lang.NoClassDefFoundError: org/springframework/core/io/Resource
通过网上通缉,在我看来,我应该有所有的.jar文件,我需要。所以,这可能是此错误的原因?
你问前:不,我不想使用Maven或摇篮这样做。这样做的目的是为了看到的一切实际上是如何工作没有任何计划做给你。
试着运行下面的命令:
~/springtutorial$ java -cp ".:spcorejars/*" com.javatpoint.Test