我正在尝试学习 Spring,并且正在关注本教程:
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>
最后,我下载了这些 Spring 核心文件:https ://www.javatpoint.com/src/sp/spcorejars.zip
通过在线查看,在我看来,我应该拥有我需要的所有 .jar 文件。那么这个错误的原因可能是什么?
在你问之前:不,我不想使用 Maven 或 Gradle 来做这件事。这样做的目的是在没有任何程序为您执行的情况下查看一切实际上是如何工作的。
凤凰求蛊
相关分类