zoukankan      html  css  js  c++  java
  • Spring 对象的声明与注入

    1、怎么把一个对象该过过交给Spring管理?

      1)通过xml中配置<bean>节点来声明

      2)通过Spring注解来声明,如:@Service、@Repository、@Component

    2、怎么把Spring容器中的对象注入到某个类的某个属性中?

      1)通过xml中配置<property>节点来注入

      2)通过Spring注解来注入,如@Autowired、@Resource

    3、几个注解的却别(@Service、@Repository、@Component、@Autowired、@Resource)

        见我的另一篇文章《Spring常用注解

    4、ApplicationContext是什么?怎么获取ApplicationContext对象?

       Application Context 是 spring 中较高级的容器。和 BeanFactory 类似,它可以加载配置文件中定义的 bean,将所有的 bean 集中在一起,当有请求的时候分配 bean。 另外,它增加了企业所需要的功能,比如,从属性文件从解析文本信息和将事件传递给所指定的监听器。

      web中,可以通过ContextLoader.getCurrentWebApplicationContext();来获取;

      main方法中,可以通过new ClassPathXmlApplicationContext或AnnotationConfigApplicationContext来获取

    5、怎么看到Spring容器的所有对象?

      获取ApplicationContext对象 --> beanFactory --> beanDefinationMap

  • 相关阅读:
    codevs1044 拦截导弹(最长不下降子序列dp)
    codevs1014 装箱问题(DP)
    codevs1068 乌龟棋(DP)
    angular.extend vs angular.copy
    angular input框点击别处 变成不可输入状态
    angular select框 option空行
    angular ui 路由传参
    setTimeout 传参
    设置请求头信息的不同方式
    vertical-align
  • 原文地址:https://www.cnblogs.com/aligege/p/8243363.html
Copyright © 2011-2022 走看看