📄 springdemo.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 + -