When you use spring there needs to be a wicket application bean defined in your applicationContext.xml, I believe the default name is "wicketApplication".

So you can instruct it to be autowired by type and then use the @Autowired annotation to get services injected into the application.

However for most cases this is not what you want. You need to consider the serialization aspects of wicket. The primary danger is that your service gets serialized with a Page or Panel and that the serialization cascades and serializes the entire spring container and all other beans. The page is serialized after each request including ajax requests.

The normal approach is to use the @SpringBean annotation within Component inheriting classes (like Page and Panel) as this will wrap your service class in a light weight proxy that can be serialized quickly and still allow the bean lookup from the application context to occur on deserialization.

The only trick is that the assignment occurs in the parent class so you need to not initialize your services to anything (otherwise you initialize the variable in the base class and it is then cleared in the current class).

Do:

@SpringBean (name="service")
private Service service;

Don't do this:
@SpringBean (name="service")
private Service service = null;

Regards,

Mike


Hi all,

I did some research within the forum but I didn't find the answer yet :(

I tried to integrate Spring (using
https://cwiki.apache.org/WICKET/spring.html#Spring-ApplicationObjectApproach
Spring + WICKET ) but I still have an error.

I added the following lines to my web.xml:

     wicket
     org.apache.wicket.protocol.http.WicketServlet

         applicationFactoryClassName
         org.apache.wicket.spring.SpringWebApplicationFactory

     1

        

     contextConfigLocation
     /WEB-INF/applicationContext.xml


     org.springframework.web.context.ContextLoaderListener


Within my xxxApplication file I added:
public class HomeApplication extends AuthenticatedWebApplication {

     private UserService userService;

     public void setUserService( UserService userService ) {
         this.userService = userService;
     }
     public UserService getUserService() {
         return this.userService;
     }

     (...)

And within my java file there is:
public class Test extends WebPage {
    private UserService getUserService() {
       return ( (xxxApplication) getApplication()).getUserService();
    }

    (...)

}

So if I start the server I invoke the setter of the method setUserService of
my xxxApplication class.
But once I call getUserService() of my java file the return value is null!?

Any ideas?
Thanks in advance.

--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/problems-with-spring-integration-tp3416484p3416484.html
Sent from the Users forum mailing list archive at Nabble.com.

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



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

Reply via email to