Home > wikikonf >  tom/actions/by kikonf > beanrsc



Action : tom.beanrsc   (Category : tom, Name : beanrsc, By : kikonf)
Complete Name :
Version : 4.0        License : Modified BSD License

Purpose of the tom category :
Easy to customize. This category use in background the Kikonf Repoz tools to create and configure Apache Tomcat root installs and Catalina bases at any level (server.xml, hosts or defaults).
You can use it to manage the whole Tomcat Architecture.

Purpose of this beanrsc plugin : This Action configures a Tomcat Bean Factory Resource.

The following shows in what part of a typical Architecture is likely to be found, the Resource configured by Action : tom.beanrsc

This Action configures a Tomcat Bean Factory Resource.

This resource factory can be used to create objects of any Java class that conforms to standard
JavaBeans naming conventions

Notice :
This documentation contains excerpts from the Tomcat official site, jndi-resources-howto.html
This documentation IS NOT the official documentation.
For the offical Tomcat doecumentation please refer to the previous Tomcat official site (

The resource factory will create a new instance for every lookup on it.


The following is a general rule for all for all the JNDI Resources configured inside Tomcat >= 5.

JNDI Resources can de declared at the global level or at the context level.

Tomcat 5 maintains a separate namespace of global resources for the entire server. 
These are configured in the <GlobalNamingResources> element of $CATALINA_BASE/conf/server.xml.
You may expose these resources to web applications by using a <ResourceLink> to include it in the per-web-application context.

Converted into the Kikonf scheme the previous stanza means that the scope for a JNDI Resource is either :
_ Global using  scope : true
_ Local using scope context (and/or an affiliated :,, default_context)

When the Global Scope is requested for an Action setting to "true" into the Action file.
The use of context (and/or an affiliated :,, default_context) is allowed.
In this case the resource is declared at the Global level.
But a ResourceLink is also created for the provided context Scope.
This is the reason why, all the Kikonf Actions for Tomcat JNDI Resources alWays support a "link" tag.


The following is a short tutorial about how to use a Bean Factory with Tomcat.

2.1. Create Your JavaBean Class

package com.mycompany;

public class MyBean {

private String foo = "Default Foo";

public String getFoo() {
return (;

public void setFoo(String foo) { = foo;

private int bar = 0;

public int getBar() {
return (;

public void setBar(int bar) { = bar;


2.2. Declare Your Resource Requirements

Add a resource-env-ref antry into your web application deployment descriptor web.xml:


2.3. Run Kikonf Action beanrsc

2.4. Sample code using the JavaBean Factory

Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
MyBean bean = (MyBean) envCtx.lookup("bean/MyBeanFactory");

writer.println("foo = " + bean.getFoo() + ", bar = " +

Trademarks :
  • "Apache", "Apache Tomcat" and "Tomcat" are trademarks of the Apache Software Foundation.
  • "Java" and "JVM" are a registred trademarks of Oracle and/or its affiliates.
  • Other names may be trademarks of their respective owners.

Copyright © 2011 - Patrick Placidoux, Hélène Malamoud