java - spring 3: inject a dependency from a library? -


i developing project , using 3rd party libraries. let's use library gives me object extobj. in project have class myobj, uses extobj. how can configure spring 3 inject extobj in myobj?

i tried research topic on internet, didn't find straight answer. use xml configuration , maybe (?) @autowired, not @ejb or @inject

thanks in advance!

update guess was:

<bean id="myobj" value="me.myobj">   <property name="extobj" value=" ... ??? ..."> </bean> 

so, don't know should put value. guess that's reference external object goes. spring can reference objects have been defined/configured in spring. so:

<bean id="extobj" value="ext.lib.extobj"> <bean id="myobj" value="me.myobj">   <property name="extobj" value="extobj"> </bean> 

is configuration right?

first need define bean extobj in application context (an xml file or @configuration class). eg. if extobj has constructor taking string can define bean way:

<bean id="extobj" class="ext.lib.extobj">     <constructor-arg value="somestring"/> </bean> 

to define myobj can use constructor injection:

<bean id="myobj" class="me.myobj">     <constructor-arg ref="extobj"/> </bean> 

or setter injection:

<bean name="myobj" class="me.myobj">     <property name="extobj" ref="extobj"/> </beans> 

if use setter injection myobj needs have setter setextobj. if use constructor injection myobj needs have constructor taking instance of extobj class.


Comments

Popular posts from this blog

Eclipse formatter for java ending braces -

ruby - Nesting modules inside of a Rails eninge gem -

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -