zoukankan      html  css  js  c++  java
  • spring依赖注入之手工装配

    2010-09-05 

    在spring中手工装配依赖对象,可以有两种方式:
    1,在spring配置文件中,通过bean节点下配置,比如:
    <bean id="service" class="com.hust.business.BuyService">
    <property name="name" value="zhangsan"/>
    <constructor-arg index="0" type="java.lang.String" value="wuhan">
    </bean>
    2,使用@Autowired或@Resource注解方式进行装配,此时需要在spring配置文件中添加以下配置:
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"  
    xsi:schemaLocation="http://www.springframework.org/schema/beans
               http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
               http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
    <context:annotation-config/>
    </beans>
    其中红色部分是要加入的内容,是使用注解功能进行注入所需要的命名空间和xml schema,该配置文件隐式注册了多个对注解进行解析处理的解析器AutowiredAnnotationBeanPostProcessor,CommonAnnotationBeanPostProcessor,PersistenceAnnotationBeanPostProcessor,RequiredAnnotationBeanPostProcessor
  • 相关阅读:
    学习进度条7
    2016年秋季个人阅读计划
    WampServer中MySQL中文乱码解决
    LINK : fatal error LNK1104: 无法打开文件“LIBCD.lib”
    人月神话阅读笔记03
    人月神话阅读笔记02
    个人总结
    人月神话阅读笔记01
    学习进度条15
    学习进度14
  • 原文地址:https://www.cnblogs.com/huapox/p/3516389.html
Copyright © 2011-2022 走看看