Embedded Tomcat and Spring

D

Darryl L. Pierce

I have an application that has embedded within it Tomcat 5.0.28. The two
portions are logically separated, but share some common objects. The
embedded Tomcat system is used for configuring the application.

I use xDoclets to generate Spring XML context files for the application
and the servlet running under Tomcat separately. But, as I mentioned
earlier, I want to share a few objects between the two. And they have to
be the same instance of each object; i.e., the instance accessed by
Tomcat needs to be the same instance accessed by the main application.

Any ideas on how to do this?
 
S

Simon OUALID

Darryl said:
Any ideas on how to do this?

Hope I understood right your request...

If so, why not use the tomcat application's context to store and share
your instances ?

FooSharedObject mySharedObject = new FooSharedObject();
getServletContext().setAttribute("sharedObject",mySharedObject);

// Then ... anywhere in another servlet.

FooSharedObject foo =
(FooSharedObject)getServletContext()
.getAttribute("sharedObject");

if (foo != null) {
// foo is initialised
// ... do some work with it
}

Symon
 
D

Darryl L. Pierce

Simon said:
Hope I understood right your request...

If so, why not use the tomcat application's context to store and share
your instances ?

That's what I want to do, but I want the shared object to be set by the
code that's *creating* the embedded instance of Tomcat. When I
instantiate the org.apache.catalina.startup.Embedded instance, I would
like to add a reference to the configuration object *at that time* to be
accessed by any servlet within the embedded Tomcat system.

Is that possible?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top