You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Valentine2008 <va...@gmail.com> on 2009/02/24 21:24:13 UTC

Hold a reference to a Spring bean in Wicket components

I am confused on this topic. 

1. In "Wicket In Action", this is a statement in "13.2.3 Using proxies
instead of direct references":
"Be careful never to hold a reference to a Spring bean in your components."

2. However, in "13.2.5 Wicket's Spring bean annotations", a reference to a
Spring bean in a Wicket component  is used: "private DiscountsService
service; " in a subclass of Panel, which is a Wicket component.

If we could hold a reference to a Spring bean in Wicket components, we have
to make the Spring bean serializable? Say DiscountsService has to extend
from Serializable?

-Valentine
-- 
View this message in context: http://www.nabble.com/Hold-a-reference-to-a-Spring-bean-in-Wicket-components-tp22189818p22189818.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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


Re: Hold a reference to a Spring bean in Wicket components

Posted by Michael O'Cleirigh <mi...@rivulet.ca>.
Hi Valentine,

If you for example have spring inject a dependency into your 
WebApplication instance and then pass this into a page like:

  private SpringBean serviceReference;

public MyPage () {

    SpringBean bean = 
((MyApplication)Application.get()).getNonProxiedSpringBean();

    this.serviceReference = bean;

..
..

In this case you have just attached a spring bean that will when 
serialized will possibly cascade through the entire spring container.  
This what your #1 is saying is bad.

What the @SpringBean annotation does is to proxy (see LazyInitProxy) the 
real bean with a static method to lookup the ApplicationContext and the 
name or unique type of the bean.  It overrides the default serialization 
behavior so that only the small proxy part is really serialized not the 
spring bean itself.

If you make you spring injected beans not serializable (i.e. don't 
implement Serializable) then in development mode wicket will throw 
serialization exceptions that will let you trackdown and remove/properly 
proxy the injected resources.

Your #2 example looks to be using this annotation/proxy based approach 
which is why it is ok.

Also be aware that you can have problems if you inject a serivce 
(properly proxied) but then extract other beans or non serializable 
resources and attach them into the model of subcomponents.  
LoadableDetachableModels can be used to handle these types of 
serialization issues.

e.g.

@SpringBean (name="service")
private Serivce s;

public MyPage () {

    add (new DropDownChoice ("choice", new Model 
(s.getInnerNonSerializableNonProxiedBean()), ...)



Mike
> I am confused on this topic. 
>
> 1. In "Wicket In Action", this is a statement in "13.2.3 Using proxies
> instead of direct references":
> "Be careful never to hold a reference to a Spring bean in your components."
>
> 2. However, in "13.2.5 Wicket's Spring bean annotations", a reference to a
> Spring bean in a Wicket component  is used: "private DiscountsService
> service; " in a subclass of Panel, which is a Wicket component.
>
> If we could hold a reference to a Spring bean in Wicket components, we have
> to make the Spring bean serializable? Say DiscountsService has to extend
> from Serializable?
>
> -Valentine
>   


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


Re: Hold a reference to a Spring bean in Wicket components

Posted by Jeremy Thomerson <je...@wickettraining.com>.
This should help:

Searching: http://www.google.com/search?q=wicket+springbean
Leads you to this as the first result:
http://cwiki.apache.org/WICKET/spring.html

And this quote: "Using annotation-based approach, you should not worry about
serialization/deserialization of the injected dependencies as this is
handled automatically, the dependencies are represented by serializable
proxies. Also, you should *not* mark you dependency properties transient
because if you do so, they won't be re-initialized upon deserialization."

So, the book is correct - the bean is not directly put into your component -
a serializable proxy is.

On Tue, Feb 24, 2009 at 2:24 PM, Valentine2008
<va...@gmail.com>wrote:

>
> I am confused on this topic.
>
> 1. In "Wicket In Action", this is a statement in "13.2.3 Using proxies
> instead of direct references":
> "Be careful never to hold a reference to a Spring bean in your components."
>
> 2. However, in "13.2.5 Wicket's Spring bean annotations", a reference to a
> Spring bean in a Wicket component  is used: "private DiscountsService
> service; " in a subclass of Panel, which is a Wicket component.
>
> If we could hold a reference to a Spring bean in Wicket components, we have
> to make the Spring bean serializable? Say DiscountsService has to extend
> from Serializable?
>
> -Valentine
> --
> View this message in context:
> http://www.nabble.com/Hold-a-reference-to-a-Spring-bean-in-Wicket-components-tp22189818p22189818.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
Jeremy Thomerson
http://www.wickettraining.com