-
Notifications
You must be signed in to change notification settings - Fork 62
项目的详细使用说明
六爷 edited this page Jan 26, 2017
·
2 revisions
Welcome to the SpringImpl_v1.0 wiki!
如果是eclispe下,直接运行clean install命令即可(把项目安装到本地仓库)
<dependency>
<groupId>spring</groupId>
<artifactId>SpringImpl</artifactId>
<version>0.0.1-SNAPSHOT</version>
public class AppTest {
private static Logger log;
DefaultListableBeanFactory defaultListableBeanFactory;
public void testDefaultListableBeanFactoryResource(){
log = LoggerFactory.getLogger(DefaultListableBeanFactory.class);
PropertyConfigurator.configure("log4j.properties");
//FileSystemResource方法的参数为bean配置文件的地址
FileSystemResource fsr=new FileSystemResource("test.xml");
try {
//注入一个resource
defaultListableBeanFactory=
new DefaultListableBeanFactory(fsr);
//到此,IOC容器defaultListableBeanFactory就已经生成完毕了
//你有两种方式从工厂中获取bean
defaultListableBeanFactory.getBean("bean的名字",bean.class);
defaultListableBeanFactory.getBean("bean的名字");
log.debug(a.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
}
附:bean.xml配置示例