Student.java
package com.javatpoint;
public class Student{
private String name;
public String getName(){
return name;
}
public void setName(String name){
this.name=name;
}
public void displayInfo(){
System.out.println("Hello"+name);
}
}
测试.java
package com.javatpoint;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResourse;
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();
}
}
applicationContext.xml
<?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: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">
<property name="name" value="Rohan"></property>
</bean>
</beans>
我已经下载了所有必需的jar文件,但仍然出现错误。因此,如何通过命令提示符运行该程序。
还有可能学习spring mvc并从头开始在线启动,如果可以,怎么办?