⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 springdemo.java

📁 Spring 为企业应用的开发提供一个轻量鼠的解决方案。该解决方案包括:基 于依赖注入的核心机制
💻 JAVA
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -