there is a way to replace constructor-arg with Annotation?
I have this constructor:
public GenericDAOImpl(Class type) {
this.type = type
Update: I'm afraid it is not possible to do what you are trying to. You can't get constructor arguments from the parameters of the injection point. A FactoryBean
would be the first place to look, but it isn't given the injection point metadata. (To be noted: this case is easily covered by CDI)
Original answer: (that may still work if you configure your types externally)
Simply use @Inject
on the constructor. But note that spring frowns upon constructor injection. Consider setter/field injection.
In your case, however, you're likely to have more than one beans of type Class
. If this is the case, you can use @Resource(name="beanName")
.
From the docs of javax.inject.Inject:
Injectable constructors are annotated with @Inject and accept zero or more dependencies as arguments. @Inject can apply to at most one constructor per class.
@Inject ConstructorModifiersopt SimpleTypeName(FormalParameterListopt) Throwsopt ConstructorBody