On 25/02/2013 18:49, Scott Ferguson wrote:
> On 2/24/13 2:54 PM, c.whalley wrote:
>> On 24/02/2013 17:21, Scott Ferguson wrote:
>>> On 2/24/13 2:06 AM, c.whalley wrote:
>>>> On 24/02/2013 05:49, Dan Ziegelbein wrote:
>>>>> The reason you're getting NPE's is that your instances of APICommand are
>>>>> not themselves injected by the container (you are instantiating them in
>>>>> code somewhere...indicated by the fact that APICommand has a
>>>>> non-injected parameterized constructor).
>>>>>
>>>>> Dan
>>>> Hi Dan & thanks for this,
>>>>
>>>> I looked more at this and realised I need to do as you say, and it seems
>>>> I need Webbeans and the @Component annotation, plus token
>>>> META-INF/web-beans.xml to mark it as so? If that's right, I'm now
>>>> struggling to even get the @Component to resolve - does the webbeans
>>>> package come with Resin or is it an external download?
>>> For Resin 4.0, it's CDI and all the names changed:
>>>
>>> the magic file in META-INF/beans.xml in a jar or WEB-INF/beans.xml for
>>> the WEB-INF/classes. The smallest content of that file "<beans/>".
>>>
>>> You don't need an annotation on the bean, but you can use something like
>>> @javax.inject.Singleton if you want it to be a single instance. The
>>> default behavior instantiates a new instance of your bean at each
>>> @Inject point.
>>>
>>> -- Scott
>> Umm ... I hope I read you right - I just added beans.xml to WEB-INF with
>> just "<beans/>" as its content and that ut is still null.
>> I did change it slightly from the code I posted earlier to ensure it
>> really is a bean, in case that was significant:
> How are you instantiating APICommand?
>
> For example, are you injecting it into your servlet?
>
> If you used "new APICommand()", CDI wouldn't be invoked, because it's
> not doing that kind of bytecode generation on the constructor.
>
> Two general patterns are:
>     @Inject APICommand _command; // injecting into another bean
>     @Inject Instance<APICommand> _factory; // creates a factory to return
> new instances
That was it - much clearer now, thanks & it all working beautifully;-)


_______________________________________________
resin-interest mailing list
resin-interest@caucho.com
http://maillist.caucho.com/mailman/listinfo/resin-interest

Reply via email to