2010-09-05 

在spring中手工装配依赖对象,可以有两种方式:
1,在spring配置文件中,通过bean节点下配置,比如:
<bean >
<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

相关文章:

  • 2021-08-07
  • 2021-12-03
  • 2021-10-10
猜你喜欢
  • 2022-02-13
  • 2021-11-20
  • 2021-09-02
  • 2022-12-23
  • 2021-06-12
  • 2021-09-29
  • 2021-07-18
相关资源
相似解决方案