File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33import org .springframework .beans .BeansException ;
44import org .springframework .context .ApplicationContext ;
55import org .springframework .context .ApplicationContextAware ;
6- import org .springframework .stereotype .Component ;
76
87/**
98 * @author zxiaofan
1211 *
1312 * private static IPrintService printService=(IPrintService) SpringContextUtil.getBean("printServiceImpl");
1413 */
15- @ Component
1614public class SpringContextUtil implements ApplicationContextAware {
1715
1816 /**
@@ -26,34 +24,35 @@ public SpringContextUtil() {
2624 /**
2725 * Spring应用上下文环境.
2826 */
29- private static ApplicationContext applicationContext ;
27+ private static ApplicationContext context ;
3028
3129 /**
3230 * {@inheritDoc}.实现ApplicationContextAware接口的回调方法,设置上下文环境.
3331 */
32+ @ Override
3433 public void setApplicationContext (ApplicationContext applicationContext ) throws BeansException {
35- SpringContextUtil . applicationContext = applicationContext ;
34+ context = applicationContext ;
3635 }
3736
3837 /**
39- * .
38+ * 获得ApplicationContext .
4039 *
4140 * @return applicationContext
4241 */
4342 public static ApplicationContext getApplicationContext () {
44- return applicationContext ;
43+ return context ;
4544 }
4645
4746 /**
48- * 根据bean名字获取bean实例,重写了bean方法,起主要作用 .
47+ * 根据bean名字获取bean实例.
4948 *
5049 * @param beanName
5150 * beanName默认为class名字(首字母小写),亦可@Service(value="printService")
52- * @return Bean
51+ * @return Bean(可能需要强转)
5352 * @throws BeansException
5453 * BeansException
5554 */
5655 public static Object getBean (String beanName ) throws BeansException {
57- return applicationContext .getBean (beanName );
56+ return context .getBean (beanName );
5857 }
5958}
You can’t perform that action at this time.
0 commit comments