我正在嘗試學習 Spring,并且正在關注本教程:https://www.javatpoint.com/spring-tutorial。這是我所做的:我創建了一個目錄springtutorial并將這兩個文件放入其中:Student.javapackage 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 來做這件事。這樣做的目的是在沒有任何程序為您執行的情況下查看一切實際上是如何工作的。
添加回答
舉報
0/150
提交
取消