Spring系列:Spring实现HelloWord

 

 

Spring系列:Spring实现HelloWord

 

Spring系列:Spring实现HelloWord

 

Spring系列:Spring实现HelloWord

 

Spring系列:Spring实现HelloWord

 

 Animal.java

Spring系列:Spring实现HelloWord
package com.project;

public class Animal {
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
Spring系列:Spring实现HelloWord

 Main.java

Spring系列:Spring实现HelloWord
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());
    }
}
Spring系列:Spring实现HelloWord

 applicationContext.xml

Spring系列:Spring实现HelloWord
<?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.1.xsd">

    <bean id="animal" class="com.project.Animal">
        <property name="name">
            <value>Dog</value>
        </property>
    </bean>
</beans>
Spring系列:Spring实现HelloWord


运行结果:

Spring系列:Spring实现HelloWord

Spring系列:Spring实现HelloWord,布布扣,bubuko.com

Spring系列:Spring实现HelloWord

上一篇:Java列表对象的性能分析和测试


下一篇:二、React使用JSX