• 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
  • 相关阅读:
    每日总结
    每日总结
    每日总结
    每日总结
    每日总结
    每日总结
    每日总结
    每日总结
    团队博客
    团队博客
  • 原文地址:https://www.cnblogs.com/huapox/p/3516389.html
Copyright © 2020-2023  润新知