You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by Neeme Praks <ne...@apache.org> on 2004/07/23 13:14:16 UTC

getting rid of static usage of Velocity in servlets

Hi all! :-)

Do you have any plans for getting rid of the static usage of Velocity 
inside Velocity*Servlet classes?

So instead of this:
public class VelocityViewServlet extends HttpServlet
{
     public void init(ServletConfig config) throws ServletException
     {
         //...
         Velocity.init();
         //...
     }

     //...

     public Template getTemplate(String name)
         throws ResourceNotFoundException, ParseErrorException, Exception
     {
         return RuntimeSingleton.getTemplate(name);
     }
}

you could do something like this:
public class VelocityViewServlet extends HttpServlet
{
     private VelocityEngine ve = ...;
     public void init(ServletConfig config) throws ServletException
     {
         //...
         ve.init();
         //...
     }

     //...

     public Template getTemplate(String name)
         throws ResourceNotFoundException, ParseErrorException, Exception
     {
         return ve.getTemplate(name);
     }
}

Why do I want to change the behaviour? Because the current 
implementation breaks if Velocity classes are loaded to a common 
classloader and then several webapps try to use it...
As it is static, it gets initialized only once and then only the first 
webapp will work, all others will usually fail to find their templates 
and will have other similar issues...

Or is there some other way out of this?

Thanks,
Neeme


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org


Re: getting rid of static usage of Velocity in servlets

Posted by Nathan Bubna <na...@esha.com>.
Neeme Praks said:
...
> Do you have any plans for getting rid of the static usage of Velocity
> inside Velocity*Servlet classes?
...

yes.  this has been a nagging issue for some time now.  i've almost got the
change all worked out, but it has turned out to be much more involved than i
first expected.  the convenience of the singleton has allowed use of it to
sneak into all sorts of little places that it probably shouldn't be.  anyway,
i hope to finish up the changes and get them in in the next few weeks, but at
present i continue to be swamped with other work and life in general.

Nathan Bubna
nathan@esha.com


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org