springdemo.java

来自「Spring 为企业应用的开发提供一个轻量鼠的解决方案。该解决方案包括:基 于」· Java 代码 · 共 40 行

JAVA
40
字号
package onlyfun.caterpillar;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

public class SpringDemo {
	

	/*
	 * 使用BeanFactory来取得beans
	*/
	public static void main(String[] args) {
		Resource rs = new ClassPathResource("beans-config.xml");
		BeanFactory factory = new XmlBeanFactory(rs);
		HelloBean hello = (HelloBean) factory.getBean("helloBean");
		System.out.println(hello.getHelloWorld());
	}
	
	/*
	 * 使用ApplicationContext取代BeanFactory,ApplicationContext除了提供
	 * BeanFactory的功能外,还提供了许多其余功能
	 * 
	 */	

//	public static void main(String[] args) {
//		ApplicationContext context= new ClassPathXmlApplicationContext("beans-config.xml");
//		HelloBean hello = (HelloBean) context.getBean("helloBean");
//		System.out.println(hello.getHelloWorld());
//	}

}

	


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?