首页 星云 工具 资源 星选 资讯 热门工具
:

PDF转图片 完全免费 小红书视频下载 无水印 抖音视频下载 无水印 数字星空

手写Spring框架源码

后端 72.74KB 32 需要积分: 1
立即下载

资源介绍:

支持高质量中文博客,希望下载者一键三连,支持知识免费分享,你的支持是我的动力!
package org.cheney.summer; import org.cheney.summer.annotation.Autowired; import org.cheney.summer.annotation.Component; import org.cheney.summer.annotation.ComponentScan; import org.cheney.summer.annotation.Scope; import java.beans.Introspector; import java.io.File; import java.lang.annotation.Annotation; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.net.URL; import java.util.ArrayList; import java.util.concurrent.ConcurrentHashMap; /** * Hello world! */ public class SummerApplicationContext { private Class configClass; private ConcurrentHashMap beanDefinitionMap = new ConcurrentHashMap<>(); private ConcurrentHashMap singletonBeanMap = new ConcurrentHashMap<>(); private ArrayList beanPostProcessorList = new ArrayList<>(); public SummerApplicationContext(Class configClass) { this.configClass = configClass; if (configClass.isAnnotationPresent(ComponentScan.class)) { ComponentScan scanAnnotation = (ComponentScan) configClass.getAnnotation(ComponentScan.class); String pathValue = scanAnnotation.value(); // org.cheney.service String[] paths = pathValue.split(","); for (String path : paths) { path = path.replace(".", "/"); ClassLoader classLoader = SummerApplicationContext.class.getClassLoader(); URL resource = classLoader.getResource(path); File file = new File(resource.getFile()); if (file.isDirectory()) { File[] files = file.listFiles(); for (File f : files) { String absolutePath = f.getAbsolutePath(); if (absolutePath.endsWith(".class")) { // 判断目录下的.class文件是否有 @Component注解 String className = absolutePath.substring(absolutePath.indexOf("org"), absolutePath.indexOf(".class")); className = className.replace("\\", "."); // System.out.println(className); try { Class clazz = classLoader.loadClass(className); if (clazz.isAnnotationPresent(Component.class)) { // 扫描到了 @Component 注解,生成一个 BeanDefinition 对象 BeanDefinition beanDefinition = new BeanDefinition(); beanDefinition.setType(clazz); if (clazz.isAnnotationPresent(Scope.class)) { String value = clazz.getAnnotation(Scope.class).value(); beanDefinition.setScope(value); } else { beanDefinition.setScope("singleton"); } String beanName = clazz.getAnnotation(Component.class).value(); if ("".equals(beanName)) { // beanName = getBeanName(clazz); beanName = Introspector.decapitalize(clazz.getSimpleName()); } beanDefinitionMap.put(beanName, beanDefinition); // 前置 后置 处理器 if (BeanPostProcessor.class.isAssignableFrom(clazz)) { BeanPostProcessor instance = (BeanPostProcessor) clazz.newInstance(); beanPostProcessorList.add(instance); } } } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (InstantiationException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } } } } } } // 将beanDefinition中的Singleton进行实例化 for (String beanName : beanDefinitionMap.keySet()) { BeanDefinition beanDefinition = beanDefinitionMap.get(beanName); if ("singleton".equals(beanDefinition.getScope())) { Object bean = createBean(beanName, beanDefinition); singletonBeanMap.put(beanName, bean); } } } private Object createBean(String beanName, BeanDefinition beanDefinition) { Class clazz = beanDefinition.getType(); try { Object bean = clazz.getConstructor().newInstance(); // 实现依赖注入 Field[] fields = clazz.getDeclaredFields(); for (Field f : fields) { if (f.isAnnotationPresent(Autowired.class)) { f.setAccessible(true); f.set(bean, getBean(f.getName())); } } // Aware 回调 if (bean instanceof BeanNameAware) { ((BeanNameAware) bean).setBeanName(beanName); } // BeanPostProcessor 初始化前,前置处理器 for (BeanPostProcessor processor : beanPostProcessorList) { processor.postProcessorBeforeInitialization(beanName,bean); } // 初始化 if (bean instanceof InitializingBean) { ((InitializingBean) bean).afterPropertiesSet(); } // BeanPostProcessor 初始化后,后置处理器 for (BeanPostProcessor processor : beanPostProcessorList) { processor.postProcessorAfterInitialization(beanName,bean); } return bean; } catch (InstantiationException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { throw new RuntimeException(e); } catch (NoSuchMethodException e) { throw new RuntimeException(e); } } public Object getBean(String beanName) { BeanDefinition beanDefinition = beanDefinitionMap.get(beanName); if (null == beanDefinition) { throw new NullPointerException("Summer容器中不存在叫做" + beanName + "的Bean"); } if (beanDefinition.getScope().equals("singleton")) { Object bean = singletonBeanMap.get(beanName); if (null == bean) { bean = createBean(beanName, beanDefinition); singletonBeanMap.put(beanName, bean); } return bean; } else { return createBean(beanName, beanDefinition); } } }

资源文件列表:

summer.zip 大约有150个文件
  1. summer/
  2. summer/.git/
  3. summer/.git/HEAD 23B
  4. summer/.git/config 130B
  5. summer/.git/description 73B
  6. summer/.git/hooks/
  7. summer/.git/hooks/applypatch-msg.sample 478B
  8. summer/.git/hooks/commit-msg.sample 896B
  9. summer/.git/hooks/fsmonitor-watchman.sample 4.62KB
  10. summer/.git/hooks/post-update.sample 189B
  11. summer/.git/hooks/pre-applypatch.sample 424B
  12. summer/.git/hooks/pre-commit.sample 1.6KB
  13. summer/.git/hooks/pre-merge-commit.sample 416B
  14. summer/.git/hooks/pre-push.sample 1.34KB
  15. summer/.git/hooks/pre-rebase.sample 4.78KB
  16. summer/.git/hooks/pre-receive.sample 544B
  17. summer/.git/hooks/prepare-commit-msg.sample 1.46KB
  18. summer/.git/hooks/push-to-checkout.sample 2.72KB
  19. summer/.git/hooks/sendemail-validate.sample 2.25KB
  20. summer/.git/hooks/update.sample 3.56KB
  21. summer/.git/index 2.9KB
  22. summer/.git/info/
  23. summer/.git/info/exclude 240B
  24. summer/.git/objects/
  25. summer/.git/objects/03/
  26. summer/.git/objects/03/96460e429caf32659d09563017833470f5e5c3 276B
  27. summer/.git/objects/08/
  28. summer/.git/objects/08/35525aac585904effeb379025707002710e381 258B
  29. summer/.git/objects/13/
  30. summer/.git/objects/13/2404bc29da2535f7f7dde84180d85abc60d5a4 303B
  31. summer/.git/objects/13/566b81b018ad684f3a35fee301741b2734c8f4 141B
  32. summer/.git/objects/2b/
  33. summer/.git/objects/2b/63946d5b31084bbb7dda418ceb3d75eb686373 1.02KB
  34. summer/.git/objects/2d/
  35. summer/.git/objects/2d/98f0c2f7411cbe38cb7ea5cb88786ed80213b3 583B
  36. summer/.git/objects/30/
  37. summer/.git/objects/30/f47ddf5c498a549d307daa02562b7acd4fe7ba 333B
  38. summer/.git/objects/32/
  39. summer/.git/objects/32/7632c7fa66c6392487157393a5f58d06307f37 193B
  40. summer/.git/objects/35/
  41. summer/.git/objects/35/e6d06d72abf2c105666f9696de018ffdf0db38 281B
  42. summer/.git/objects/3a/
  43. summer/.git/objects/3a/eea94ed547bf089680d26b245f0871c8b99f69 242B
  44. summer/.git/objects/3c/
  45. summer/.git/objects/3c/02a49d0b997d4bdf0df753fc1e879eb387844a 234B
  46. summer/.git/objects/42/
  47. summer/.git/objects/42/2312da4af1465331644bfb9c9e251ccf838195 263B
  48. summer/.git/objects/4d/
  49. summer/.git/objects/4d/3a03b2c175f3f9b57c7134bd8829ce5feab4ae 261B
  50. summer/.git/objects/59/
  51. summer/.git/objects/59/67db551127860c6b4dd39ed7c2a58cf8ff033b 410B
  52. summer/.git/objects/6b/
  53. summer/.git/objects/6b/ab5e73d23a08e2eed8bd5bd056a350ac9359b8 216B
  54. summer/.git/objects/71/
  55. summer/.git/objects/71/2ab9d985c20018a0c97b93d2148ac1ffe588a5 300B
  56. summer/.git/objects/73/
  57. summer/.git/objects/73/2621e6cdca228debecd47e030e6d824e4eccf4 342B
  58. summer/.git/objects/89/
  59. summer/.git/objects/89/8ea3b6409bcc78d16be4c9cea283d5c429d2aa 206B
  60. summer/.git/objects/90/
  61. summer/.git/objects/90/f23a08a77b9f8b8c4b414bf830b18516be5b20 2.01KB
  62. summer/.git/objects/94/
  63. summer/.git/objects/94/a25f7f4cb416c083d265558da75d457237d671 155B
  64. summer/.git/objects/94/ff652c729a68c45294fe4e2ebdf0dd7d7a7704 176B
  65. summer/.git/objects/9a/
  66. summer/.git/objects/9a/161ea3bf82d7c21ad98b38cb266082248ea0ae 214B
  67. summer/.git/objects/9a/4ac8f7823350ecb6cc73fcb8d6f0c40395fad0 260B
  68. summer/.git/objects/9a/ff25c06ebf5dd2b80d0544951e94bac3d4183a 170B
  69. summer/.git/objects/a8/
  70. summer/.git/objects/a8/fcc84db3668cadd75348be61bda65a8fc5ea21 800B
  71. summer/.git/objects/aa/
  72. summer/.git/objects/aa/00ffab7828f4818589659c804ec2cfd99baed3 170B
  73. summer/.git/objects/bc/
  74. summer/.git/objects/bc/c8ad448113f8c8bf401a52fea2bf58b36a3107 239B
  75. summer/.git/objects/d7/
  76. summer/.git/objects/d7/e995c756a458a5cae4ad685251f15c9a4e0918 1.25KB
  77. summer/.git/objects/info/
  78. summer/.git/objects/pack/
  79. summer/.git/refs/
  80. summer/.git/refs/heads/
  81. summer/.git/refs/tags/
  82. summer/.gitignore 400B
  83. summer/.idea/
  84. summer/.idea/.gitignore 184B
  85. summer/.idea/compiler.xml 539B
  86. summer/.idea/encodings.xml 267B
  87. summer/.idea/jarRepositories.xml 864B
  88. summer/.idea/markdown-navigator-enh.xml 2.12KB
  89. summer/.idea/markdown-navigator.xml 3.81KB
  90. summer/.idea/misc.xml 541B
  91. summer/.idea/uiDesigner.xml 8.71KB
  92. summer/.idea/vcs.xml 185B
  93. summer/.idea/workspace.xml 7.66KB
  94. summer/pom.xml 1.49KB
  95. summer/src/
  96. summer/src/main/
  97. summer/src/main/java/
  98. summer/src/main/java/org/
  99. summer/src/main/java/org/cheney/
  100. summer/src/main/java/org/cheney/SummerApplication.java 847B
  101. summer/src/main/java/org/cheney/config/
  102. summer/src/main/java/org/cheney/config/AppBeanPostProcessor.java 757B
  103. summer/src/main/java/org/cheney/config/AppConfig.java 255B
  104. summer/src/main/java/org/cheney/service/
  105. summer/src/main/java/org/cheney/service/Admin.java 773B
  106. summer/src/main/java/org/cheney/service/OrderService.java 301B
  107. summer/src/main/java/org/cheney/service/User.java 313B
  108. summer/src/main/java/org/cheney/service/UserService.java 392B
  109. summer/src/main/java/org/cheney/summer/
  110. summer/src/main/java/org/cheney/summer/BeanDefinition.java 643B
  111. summer/src/main/java/org/cheney/summer/BeanNameAware.java 193B
  112. summer/src/main/java/org/cheney/summer/BeanPostProcessor.java 318B
  113. summer/src/main/java/org/cheney/summer/InitializingBean.java 195B
  114. summer/src/main/java/org/cheney/summer/SummerApplicationContext.java 7.24KB
  115. summer/src/main/java/org/cheney/summer/annotation/
  116. summer/src/main/java/org/cheney/summer/annotation/Autowired.java 393B
  117. summer/src/main/java/org/cheney/summer/annotation/Component.java 424B
  118. summer/src/main/java/org/cheney/summer/annotation/ComponentScan.java 428B
  119. summer/src/main/java/org/cheney/summer/annotation/Scope.java 420B
  120. summer/src/test/
  121. summer/src/test/java/
  122. summer/src/test/java/org/
  123. summer/src/test/java/org/cheney/
  124. summer/src/test/java/org/cheney/MainTest.java 324B
  125. summer/target/
  126. summer/target/classes/
  127. summer/target/classes/org/
  128. summer/target/classes/org/cheney/
  129. summer/target/classes/org/cheney/SummerApplication.class 1.05KB
  130. summer/target/classes/org/cheney/config/
  131. summer/target/classes/org/cheney/config/AppBeanPostProcessor.class 1.26KB
  132. summer/target/classes/org/cheney/config/AppConfig.class 427B
  133. summer/target/classes/org/cheney/service/
  134. summer/target/classes/org/cheney/service/Admin.class 969B
  135. summer/target/classes/org/cheney/service/OrderService.class 627B
  136. summer/target/classes/org/cheney/service/User.class 438B
  137. summer/target/classes/org/cheney/service/UserService.class 644B
  138. summer/target/classes/org/cheney/summer/
  139. summer/target/classes/org/cheney/summer/BeanDefinition.class 951B
  140. summer/target/classes/org/cheney/summer/BeanNameAware.class 171B
  141. summer/target/classes/org/cheney/summer/BeanPostProcessor.class 262B
  142. summer/target/classes/org/cheney/summer/InitializingBean.class 166B
  143. summer/target/classes/org/cheney/summer/SummerApplicationContext.class 7.08KB
  144. summer/target/classes/org/cheney/summer/annotation/
  145. summer/target/classes/org/cheney/summer/annotation/Autowired.class 399B
  146. summer/target/classes/org/cheney/summer/annotation/Component.class 461B
  147. summer/target/classes/org/cheney/summer/annotation/ComponentScan.class 469B
  148. summer/target/classes/org/cheney/summer/annotation/Scope.class 453B
  149. summer/target/generated-sources/
  150. summer/target/generated-sources/annotations/
0评论
提交 加载更多评论
其他资源 C语言期末模拟卷.zip
C语言期末模拟卷.zip
C语言期末模拟卷.zip C语言期末模拟卷.zip
RPA Taskt可执行exe程序(Robot Framework、Taskt、UI.Vision、OpenRPA和TagUI)
当前RPA的开源市场中,备受推荐的框架有:Robot Framework、Taskt、UI.Vision、OpenRPA和TagUI。 以下是这5个开源框架在低代码、可读性、跨平台、开发语言、以及开源协议等方面的对比. taskt(原名sharpRPA)是基于.NET Framework的C#开发的一款免费、易于使用的开放源代码自动化客户端。它的设计理念就是让用户能够构建和设计流程自动化,而不需要编写一行应用代码。借助taskt,你可以轻松实现繁杂任务的自动化,并打造出自己的数字工作团队。 环境要求: 1、windows操作系统 2、.NET框架4.8 详解介绍与使用:https://mp.csdn.net/mp_blog/creation/editor/142444808
大地坐标与空间直角坐标相互转换
基于实现同一坐标系下,空间直角坐标和大地坐标的转换问题,运用窗体实现数据的单点计算和数据(.txt格式)的计算和计算结果的输出为.txt格式。
eba轮播js广告代码
eba轮播js广告代码
CU3ER官网flash 3D焦点图代码
CU3ER官网flash 3D焦点图代码
CU3ER官网flash 3D焦点图代码
CSS3窗帘式4格焦点图代码,带有数字导航,点击数字之后图片会以窗帘形式切换
CSS3窗帘式4格焦点图代码,带有数字导航,点击数字之后图片会以窗帘形式切换,另外共有4种图片切换样式可以选择,兼容主流浏览器,模板在线推荐下载! 使用方法: 1、head区域引用文件htmldivcss.css 2、在文件中加入区域代码 3、图片路径请打开htmldivcss.css修改
ChinaRen首页flash轮换代码
ChinaRen首页flash轮换代码
ChinaRen首页5屏Flash焦点图
ChinaRen首页5屏Flash焦点图