Hello,

I am not entirely sure if I understand your question correctly. But I
usually use Spring like this:

YourDao (either defined in applicationContext.xml or in separate
spring-config files, or annotation-driven e.g. with @Repository. The
template you mention I usually autowire into the dao so basically it
looks like (this example is annotation-driven):

@Repository (value="myDao")
class YourDao {

   @Autowired
   private YourTemplate yourTemplate;


   public void xxx() {
     // use your template here
   }
}

In Wicket you can then use :

@SpringBean (name="myDao")
private YourDao yourDao;

You can do the same using wiring through xml files, the idea is the
same nevertheless. If you need 'larger' services I'd advice to use a
service layer (which uses multiple dao's or whatever is needed to do
the work in a single transaction), the latter is just a matter of
taste.

Martijn

On Tue, Feb 17, 2009 at 5:55 PM, Sergey Podatelev
<[email protected]> wrote:
> Okay, this question might actually be more related to Spring, but I'm
> completely lost here, and my question on Spring forums usually don't get any
> replies, so I hope Wicket community might help as it usually does.
>
> I'm using JCR, and have a RepositoryDao bean configured in
> applicationContext.xml.
> RepositoryDao has a "template" property which points to an instance of
> JcrTemplate in applicationContext.xml, all repository access is performed
> through that template.
>
> I have an AccessPage which has a RepositoryDao injected via @SpringBean.
> There is an inner class Form on that page, it has a default submit button
> and three submit buttons that skip default processing and perform their own
> operations onSubmit(). Both default button and skip-default-processing
> buttons use the same repositoryDao property of AccessPage to perform certain
> operations on repository.
>
> I noticed that when I actually open that AccessPage, there's a new
> RepositoryDao object created, and it's "template" property is null. When I
> press any of those non-default submit buttons of the form, everything works
> fine. But on default button onSubmit(), I see that there's yet another
> insance of RepositoryDao created, and it's "template" is also null, which
> leads to NullPointerException.
>
> I assumed that beans configured in applicationContext.xml are actually
> singletons, so there won't be any new instances of such nodes upon
> pages-with-injections instantiation.
>
> Regardless of whether that assumption is correct/incorrect/my-god-rtfm, I
> still won't understand why default submit button reaction is NPE as it uses
> same partnershipDao property of AccessPage.
>
> Could someone please elaborate some internal differences of the
> annotation-based approach as opposed to storing DAOs in Application object.
> In the latter case it's quite clear that there's a single instance of
> RepositoryDao as a property of MyApplication which is pulled on
> ((MyApplication) Application.get()).getRepositoryDao().
>
> Thanks.
>
> --
> sp
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to