You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Vladimir Bauer <VB...@slb.com> on 2012/07/24 21:17:31 UTC

Injecting spring beans not in pages package

Hi!

I'm using spring dataDao in my tapestry 5 application.
Tapestry's filter used is org.apache.tapestry5.spring.TapestrySpringFilter in web.xml

I can inject my dataDao in com.myapp.pages package, there is no problem.
But I have a package com.myapp.model where I need to use dataDao as well, injecting doesn't work in this package, I end up with null pointer exception.
So as workaround I have to pass my dataDao bean from pages classes to model classes as argument in constructor of any model's class.

Could someone point the correct way to inject spring dao not in pages package, but some other in same web application.

Regards,
Vladimir Bauer



Re: Injecting spring beans not in pages package

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Tue, 24 Jul 2012 16:17:31 -0300, Vladimir Bauer <VB...@slb.com> wrote:

> Hi!

Hi!

> I can inject my dataDao in com.myapp.pages package, there is no problem.
> But I have a package com.myapp.model where I need to use dataDao as  
> well, injecting doesn't work in this package, I end up with null pointer  
> exception.

In pages, components and mixins, Tapestry injects services (including  
Spring beans if tapestry-spring is used and correctly configured).

Tapestry-IoC injection only works in objects instatiated by itself. If you  
want to inject Spring beans into objects, you either turn them into Spring  
beans, Tapestry-IoC services or you inject ObjectLocator and use its  
getService() methods to get the services/beans programatically.

> So as workaround I have to pass my dataDao bean from pages classes to  
> model classes as argument in constructor of any model's class.

What do you mean by model classes?

-- 
Thiago H. de Paula Figueiredo

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org