File tree Expand file tree Collapse file tree 5 files changed +33
-18
lines changed
src/main/java/us/codecraft/tinyioc/context Expand file tree Collapse file tree 5 files changed +33
-18
lines changed Original file line number Diff line number Diff line change 1- tinyioc
1+ tiny-spring
22=======
33
44A tiny IoC container refer to Spring.
Original file line number Diff line number Diff line change 1- tiny-IoC
1+ tiny-spring
22=====
33
44步骤:
Original file line number Diff line number Diff line change 11<?xml version =" 1.0" encoding =" UTF-8" ?>
22<project xmlns =" http://maven.apache.org/POM/4.0.0" xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance" xsi : schemaLocation =" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
33 <groupId >us.codecraft</groupId >
4- <artifactId >tiny-ioc </artifactId >
5- <version >0.1 .1-SNAPSHOT</version >
4+ <artifactId >tiny-spring </artifactId >
5+ <version >0.0 .1-SNAPSHOT</version >
66 <modelVersion >4.0.0</modelVersion >
77 <packaging >jar</packaging >
88 <properties >
99 <project .build.sourceEncoding>UTF-8</project .build.sourceEncoding>
1010 <project .reporting.outputEncoding>UTF-8</project .reporting.outputEncoding>
1111 </properties >
12- <name >tiny-ioc </name >
12+ <name >tiny-spring </name >
1313 <description >
14- A tinu ioc container for study.
14+ A tiny implementation of Spring for study.
1515 </description >
1616 <url >https://github.com/code4craft/xsoup/</url >
1717 <developers >
Original file line number Diff line number Diff line change 1+ package us .codecraft .tinyioc .context ;
2+
3+ import us .codecraft .tinyioc .beans .factory .AbstractBeanFactory ;
4+
5+ /**
6+ * @author yihua.huang@dianping.com
7+ */
8+ public abstract class AbstractApplicationContext implements ApplicationContext {
9+ protected AbstractBeanFactory beanFactory ;
10+
11+ public AbstractApplicationContext (AbstractBeanFactory beanFactory ) {
12+ this .beanFactory = beanFactory ;
13+ }
14+
15+ public abstract void refresh () throws Exception ;
16+
17+ @ Override
18+ public Object getBean (String name ) {
19+ return beanFactory .getBean (name );
20+ }
21+ }
Original file line number Diff line number Diff line change 1111/**
1212 * @author yihua.huang@dianping.com
1313 */
14- public class ClassPathXmlApplicationContext implements ApplicationContext {
14+ public class ClassPathXmlApplicationContext extends AbstractApplicationContext {
1515
16- private AbstractBeanFactory beanFactory ;
17-
18- private String configLocation ;
16+ private String configLocation ;
1917
2018 public ClassPathXmlApplicationContext (String configLocation ) {
2119 this (configLocation , new AutowireCapableBeanFactory ());
2220 }
2321
2422 public ClassPathXmlApplicationContext (String configLocation , AbstractBeanFactory beanFactory ) {
25- this . configLocation = configLocation ;
26- this .beanFactory = beanFactory ;
23+ super ( beanFactory ) ;
24+ this .configLocation = configLocation ;
2725 try {
2826 refresh ();
2927 } catch (Exception e ) {
3028 e .printStackTrace ();
3129 }
3230 }
3331
34- public void refresh () throws Exception {
32+ @ Override
33+ public void refresh () throws Exception {
3534 XmlBeanDefinitionReader xmlBeanDefinitionReader = new XmlBeanDefinitionReader (new ResourceLoader ());
3635 xmlBeanDefinitionReader .loadBeanDefinitions (configLocation );
3736 for (Map .Entry <String , BeanDefinition > beanDefinitionEntry : xmlBeanDefinitionReader .getRegistry ().entrySet ()) {
3837 beanFactory .registerBeanDefinition (beanDefinitionEntry .getKey (), beanDefinitionEntry .getValue ());
3938 }
4039 }
4140
42- @ Override
43- public Object getBean (String name ) {
44- return beanFactory .getBean (name );
45- }
46-
4741}
You can’t perform that action at this time.
0 commit comments