struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Aum Strut <>
Subject Re: How to get instance of the given dependency using Container
Date Mon, 01 Oct 2012 17:12:11 GMT
I am still confused the way Struts2 internal DI and container.getInstance()
since i have this inside my class

private Class provider;
public void setProvider( Class<? extends Provider> provider)
        this.provider = provider;

So if at run time i want to inject my provider, so i will be declaring a
constant for my plugin say

<constant name="' value="">

so i believe now i have to do the following steps

1. Get an instance of the provider based on the constant name
2. Init my provider with the instance i got from Struts2 DI

so i guess i need to do this either in init method or my bean constructor



but above will not work ,since as per the getInstance() method
signature <T>T getInstance
(Class<T> type, String name)
i will getting instance of Provider class and which means either i have to
change the signature of  public void setProvider( Class<? extends Provider>

which means loosing the generics capability as my intentions are to inject
any class which extends Provider.

i am all confused here and not sure what exact is to do, nor i want to add
any further dependencies.

Any suggestion as how to achieve this?


On Mon, Oct 1, 2012 at 6:09 PM, Lukasz Lenart <>wrote:

> 2012/10/1 Aum Strut <>:
> > i was thinking about a way like Spring DI used to do something like
> >
> > <bean type="" class="" name="impl1" >
> >    <property name="a" value="Run time class"/>
> > </bean>
> >
> > It would be more convient to have injection like this way.
> Just annotate your setter with @Inject(name="a") and create constant
> in struts.xml. If "a" is a String value.
> Regards
> --
> Ɓukasz
> + 48 606 323 122
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message