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-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to