Juergen Donnerstag wrote:
What is the use case where the context can not be found via
WebApplicationContextUtils.getRequiredApplicationContext(aServletContext).?
  
The use case is where existing code is used which has its own method of accessing Spring configuration such as using

 BeanFactoryLocator locator = ContextSingletonBeanFactoryLocator
                    .getInstance(aSelector);

In this case using both the WebApplicationContextUtils and the ContextSingletonBeanFactoryLocator could lead to duplicate
instantiations of objects that could be undesired.

Also,
  • sometimes a lookup cannot be avoided in legacy code (e.g. stateless session bean) and there it would be strange to use WebApplicationContextUtils,
  • sometimes lookups are already present in existing code and we simply want to ensure that the same lookup mechanism is used also by wicket.

Of course, with a proper design, injection would solve all problems since no lookup would be required anymore anywhere in the code.

My point is just that the lookup mechanism of the ApplicationContext should be defined in one place only and that it should not be restricted to WebApplicationContextUtils. Currently, SpringComponentInjector violates this principle.

I already have a modified version (adapted copy) working.

The relevant part of the code is this:

   /**
     * Constructor for web applications. This uses
     * [EMAIL PROTECTED] WebApplicationContextUtils#getRequiredWebApplicationContext(ServletContext)} to
     * locate the application context.
     *
     * @param webapp
     */
    public SpringComponentInjector(WebApplication webapp) {
        this(webapp, getWebApplicationContext(webapp));
    }
   
    /**
     * Gets the web application context using
     * [EMAIL PROTECTED] WebApplicationContextUtils#getRequiredWebApplicationContext(ServletContext)}.
     * @param webapp Web application.
     */
    private static ApplicationContext getWebApplicationContext(WebApplication webapp) {
        // locate spring's application context ...
        ServletContext sc = webapp.getWicketServlet().getServletContext();

        return WebApplicationContextUtils
                .getRequiredWebApplicationContext(sc);
    }

    /**
     * Constructor for web appliactions.
     *
     * @param aWebapp The web application
     * @param aContext The spring application context.
     */
    public SpringComponentInjector(WebApplication aWebapp, final ApplicationContext aContext) {
        // ... stash the holder to the context in the application's metadata ...
        aWebapp.setMetaData(CONTEXT_KEY, new ApplicationContextHolder(aContext));

        // ... and create and register the annotation aware injector
        InjectorHolder
                .setInjector(new AnnotSpringInjector(new ContextLocator()));
    }
Juergen

On 9/3/06, Erik Brakkee <[EMAIL PROTECTED]> wrote:
  
Hi,


I have done some work to locate the Spring application context in
another way. Both wicket-spring and wicket-spring-annot assume that the
application context can be obtained with
WebApplicationContextUtils.getRequiredApplicationContext(aServletContext).

Luckily, it is easy to write my own IWebApplicationFactory which does
the appropriate lookup and I am still able to extend
SpringWebApplication. Nevertheless, this does not work because
SpringComponentInjector also hardcodes a lookup of the application
context using WebApplicationContextUtils.

The code is like this:

public SpringComponentInjector(WebApplication webapp) {
                // locate spring's application context ...
                ServletContext sc =
webapp.getWicketServlet().getServletContext(
);

                final ApplicationContext ctx = WebApplicationContextUtils
                                .getRequiredWebApplicationContext(sc);

                 ....
}

In other words, a redundancy. In my opinion, the code should be modified
as follows:

1. Add a new constructor which accepts the ApplicationContext as a
parameter.
2. Remove the existing constructor with the WebApplication OR document
it to use the WebApplicationContextUtils
   for retrieving the application context

What do you think?

Cheers
  Erik





-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

    

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user
  

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to