Animal.java
package com.project;public class Animal { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; }}
Main.java
package com.project;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 Main { public static void main(String[] args) { Resource resource=new ClassPathResource("applicationContext.xml"); BeanFactory beanFactory=new XmlBeanFactory(resource); Animal animal=(Animal)beanFactory.getBean("animal"); System.out.println(animal.getName()); }}
applicationContext.xml
Dog