Spring Framework项目创建
再resource目录下创建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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="video" class="com.example.demo01.domain.Video">
<property name="id" value="25"/>
<property name="title" value="hello world"/>
</bean>
</beans>
再创建入口类
public class App {
    public static void main(String[] args) {
//引用配置文件
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
//获取配置文件中id为"video"的bean
        Video video = (Video) applicationContext.getBean("video");
        System.out.println(video.getTitle());
    }
}
其中   Video类中只有简单的id、title及其getter,setter方法
最后再运行入口类,成功打印hello world!
 
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号