【发布时间】:2012-08-08 10:12:09
【问题描述】:
在我使用 Spring 容器的应用程序中,我创建了自己的注解,并且我希望在运行时获取使用我的注解进行注解的类的 Class 对象。为此,我想使用 Spring 容器。
在我的 .xml 配置文件中放置
<context:component-scan base-package="some.package" >
<context:include-filter type="annotation" expression="some.package.Question" />
</context:component-scan>
因此 Spring 检测到使用我的 Question 注释注释的类。问题是这些类没有参数构造函数,所以现在我有两个选择:
- 在这些类中定义无参数构造函数
- 在.xml 中定义bean 并使用constructor-arg
但是是否可以用一些注解来注解构造函数参数,所以 Spring 会知道它需要在创建 bean 期间传递 null 值?
这些 bean 也将具有原型范围,并且从应用程序的角度来看,构造函数参数的内容在创建 bean 期间是未知的。
编辑:
我不得不使用 @Value("#{null}") 注释构造函数参数
【问题讨论】:
标签: spring dependency-injection