You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "John D. Ament" <jo...@apache.org> on 2016/12/14 03:13:27 UTC

Populating init parameters

Hi,

I'm using Tomcat embedded to start a container.  I need to set some
initParameters in that embedded runtime.  However, when I try to set the
parameters I get the follow:

java.lang.IllegalStateException: Initialization parameters cannot be set
after the context has been initialized

at
org.apache.catalina.core.ApplicationContext.setInitParameter(ApplicationContext.java:1003)
at
org.apache.catalina.core.ApplicationContextFacade.setInitParameter(ApplicationContextFacade.java:624)

I'm using the following to set the init parameter:

Context ctx = tomcat.addContext("",base.getAbsolutePath());
ServletContext servletContext = ctx.getServletContext();
servletContext.setInitParameter("key","value");

When i look, the tomcat instance is in the new state.  So it hasn't been
initialized yet.  I was wondering if this was an error?  I'm using Tomcat
8.5.9.
John

Re: Populating init parameters

Posted by "John D. Ament" <jo...@apache.org>.
Mark,

On Wed, Dec 14, 2016 at 3:10 AM Mark Thomas <ma...@apache.org> wrote:

> On 14/12/2016 03:13, John D. Ament wrote:
> > Hi,
> >
> > I'm using Tomcat embedded to start a container.  I need to set some
> > initParameters in that embedded runtime.  However, when I try to set the
> > parameters I get the follow:
> >
> > java.lang.IllegalStateException: Initialization parameters cannot be set
> > after the context has been initialized
> >
> > at
> >
> org.apache.catalina.core.ApplicationContext.setInitParameter(ApplicationContext.java:1003)
> > at
> >
> org.apache.catalina.core.ApplicationContextFacade.setInitParameter(ApplicationContextFacade.java:624)
> >
> > I'm using the following to set the init parameter:
> >
> > Context ctx = tomcat.addContext("",base.getAbsolutePath());
> > ServletContext servletContext = ctx.getServletContext();
> > servletContext.setInitParameter("key","value");
> >
> > When i look, the tomcat instance is in the new state.  So it hasn't been
> > initialized yet.  I was wondering if this was an error?  I'm using Tomcat
> > 8.5.9.
>
> The error message might need a tweak for the embedded case but it is
> telling you the ServletContext is in the wrong state for editing the
> parameters.
>
> You want to add addParameter() on the Context object.
>

That worked.  Thanks.


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

Re: Populating init parameters

Posted by Mark Thomas <ma...@apache.org>.
On 14/12/2016 03:13, John D. Ament wrote:
> Hi,
> 
> I'm using Tomcat embedded to start a container.  I need to set some
> initParameters in that embedded runtime.  However, when I try to set the
> parameters I get the follow:
> 
> java.lang.IllegalStateException: Initialization parameters cannot be set
> after the context has been initialized
> 
> at
> org.apache.catalina.core.ApplicationContext.setInitParameter(ApplicationContext.java:1003)
> at
> org.apache.catalina.core.ApplicationContextFacade.setInitParameter(ApplicationContextFacade.java:624)
> 
> I'm using the following to set the init parameter:
> 
> Context ctx = tomcat.addContext("",base.getAbsolutePath());
> ServletContext servletContext = ctx.getServletContext();
> servletContext.setInitParameter("key","value");
> 
> When i look, the tomcat instance is in the new state.  So it hasn't been
> initialized yet.  I was wondering if this was an error?  I'm using Tomcat
> 8.5.9.

The error message might need a tweak for the embedded case but it is
telling you the ServletContext is in the wrong state for editing the
parameters.

You want to add addParameter() on the Context object.

Mark


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