Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring p namespace for constructor args?

Tags:

java

spring

Is there an equivalent of the p namespace for constructor args in Spring? I would love to shorten that XML :)

like image 595
Cristian Vrabie Avatar asked Oct 07 '11 08:10

Cristian Vrabie


1 Answers

No, there is no equivalent for constructor injection prior to 3.1, but you may consider autowiring the constructor in your XML like this:

<bean id="beanId" class="..." autowire="constructor"/>

By autowiring, you do not have to specify the individual constructor args here as spring will work them out, just make sure you only have one bean of each type or spring will not be able to autowire them.

EDIT:

as @gkamal stated, from spring 3.1 onwards you can use the c namespace for constructor injection.

like image 112
krock Avatar answered Oct 18 '22 19:10

krock