You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Rick Reumann <ri...@gmail.com> on 2007/09/18 22:56:14 UTC
Question about best approach using Spring
I've looked at the wiki post here about Spring:
http://cwiki.apache.org/WICKET/spring.html
I'm curious about 'best approaches' and if you bare with me I'll explain my
concern, but let me first address what I'll want to do..
In a WebApplication, SpringWebApplication, or possibly a WebPage, I'd like
to use a BusinessDelegate/serviceClass that in turn has a DAO that is Spring
injected into the BusinessDelegate. (I might also inject the
BusinessDelegate, but for now lets assume I'm not). So we have....
Wicket Object (as WebApp, Webpage, etc)
|
-------> BusinessDelegate
|
----------> DAO //Spring injected
In a Struts application I'd just declare the beans I want to inject and into
what classes in my applicationContext.xml file.
Reading the wiki I understand that your wicket objects might be serialized
which creates some problems.
My first thought was to mark my BusinessDelegate transient in my wicket
object, and then when its needed, do the null check, and if null create a
new instance which would in turn use the LazyInitProxyFactory to load the
dao it needs.
The problem with this, though, is I'd now have to use wicket classes
(LazyInitProxyFactory) in my BusinesDelegate which I was hoping could remain
completely agnostic of the front end technology (if someone else in another
application wanted to use this delegate, I don't want them having to import
Wicket classes.)
Would it work instead if I injected the DAO in the BusinessDelegate using
the traditional approach (simple definition in applicationContext.xml), but
then used the proxy approach in the Wicket object that would create the
BusinessDelegate: (SomeBusinessDelegate)createSpringBeanProxy(
SomeBusinessDelegate.class, "myDelegate"); ?
(Slight drawaback to this is I'd have to define all the BusinessDelegates as
spring managed objects - but I can deal with that since it's not a bad
practice anyway.)
Re: Question about best approach using Spring
Posted by Rick Reumann <ri...@gmail.com>.
On 9/19/07, John Krasnay <jo...@krasnay.ca> wrote:
>
>
> Sounds like you still need a Spring context for your unit tests, to give
> createSpringBeanProxy something to work with. Not a huge deal but still
> a minor complication. With the annotation approach, I can just ignore
> the annotation and inject a stub using the setter. But if you can't use
> Java5 it's kinda moot.
Thanks John, excellent point. Actually I think this really throws a wrench
into my testing. I'm not sure what SpringWebApplication class has going on
behind the scenes that I'm relying on for Spring injection.
Those that have used this proxy approach before with SpringWebApplication,
are there some examples how to run your unit tests with this in place?
-
Rick
Re: Question about best approach using Spring
Posted by John Krasnay <jo...@krasnay.ca>.
On Wed, Sep 19, 2007 at 09:05:48AM -0400, Rick Reumann wrote:
>
> Yea, I'd like to use the annotation but I believe that's only working when
> running under Java5? (sadly, this app has to run on an old websever that is
> using Java4.) (The annotation is in the wicket-contrib-spring-jdk5 so I just
> figured it required Java5 - but I'm not positive of that requirement - can
> someone confirm ? )
Yup, Java5 is required for annotations.
> Also, where you mention "allows me to manually inject test instances of my
> services/business
> delegates to do unit tests." - I get the same benefit with the proxy
> approach which is why I'm using Spring in the first place:) - it's just
> slightly more verbose, although if I use the 'createSpringBeanProxy' from my
> Base application class it's really only one line so it's not 'that' bad -
> unless there is something else that annotation approach gives me that I'm
> missing?
Sounds like you still need a Spring context for your unit tests, to give
createSpringBeanProxy something to work with. Not a huge deal but still
a minor complication. With the annotation approach, I can just ignore
the annotation and inject a stub using the setter. But if you can't use
Java5 it's kinda moot.
jk
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Question about best approach using Spring
Posted by Rick Reumann <ri...@gmail.com>.
On 9/18/07, John Krasnay <jo...@krasnay.ca> wrote:
>
>
> public class MyPage extends WebPage {
>
> @SpringBean
> public SomeService someService;
>
> public MyPage() {
> someService.doSomething();
> }
> }
>
> Using an annotation instead of calling createSpringBeanProxy directly
> allows me to manually inject test instances of my services/business
> delegates to do unit tests.
Yea, I'd like to use the annotation but I believe that's only working when
running under Java5? (sadly, this app has to run on an old websever that is
using Java4.) (The annotation is in the wicket-contrib-spring-jdk5 so I just
figured it required Java5 - but I'm not positive of that requirement - can
someone confirm ? )
Also, where you mention "allows me to manually inject test instances of my
services/business
delegates to do unit tests." - I get the same benefit with the proxy
approach which is why I'm using Spring in the first place:) - it's just
slightly more verbose, although if I use the 'createSpringBeanProxy' from my
Base application class it's really only one line so it's not 'that' bad -
unless there is something else that annotation approach gives me that I'm
missing?
Re: Question about best approach using Spring
Posted by John Krasnay <jo...@krasnay.ca>.
On Tue, Sep 18, 2007 at 04:56:14PM -0400, Rick Reumann wrote:
> I've looked at the wiki post here about Spring:
> http://cwiki.apache.org/WICKET/spring.html
>
> I'm curious about 'best approaches' and if you bare with me I'll explain my
> concern, but let me first address what I'll want to do..
>
I suppose "best approaches" is subjective, but I prefer the @SpringBean
annotations in my pages:
public class App extends WebApplication implements ISpringContextLocator
{
public ApplicationContext getSpringContext() {
return WebApplicationContextUtils.getWebApplicationContext(getServletContext());
}
protected void init() {
super.init();
addComponentInstantiationListener(new SpringComponentInjector(this));
}
}
public class MyPage extends WebPage {
@SpringBean
public SomeService someService;
public MyPage() {
someService.doSomething();
}
}
Using an annotation instead of calling createSpringBeanProxy directly
allows me to manually inject test instances of my services/business
delegates to do unit tests.
> (Slight drawaback to this is I'd have to define all the BusinessDelegates as
> spring managed objects - but I can deal with that since it's not a bad
> practice anyway.)
I'd call it a good thing.
jk
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org