JAXB Bean configuration
Resin 3.1

Documentation
Examples
Changes

Quercus
Database
Amber
EJB
SOA/ESB
IoC
JMS
Servlet
JMX
Hessian
Security

JAXB IoC
Basic Resource
Injection
Periodic Task
JNDI appconfig
IoC
IoC
Basic Resource

Resin's configuration integrates JAXB-style bean configuration.

Demo

With Resin, applications can use JAXB to configure its resources directly from the resin.conf or resin-web.xml. A "JAXB Bean" is just a Java class that follows a simple set of rules. Each configuration parameter foo has a corresponding setter method setFoo with a single argument for the value. Resin can look at the class using Java's reflection and find the setFoo method. Because Resin can find the bean-style setters from looking at the class, it can configure those setters in a configuration file like the resin-web.xml.

Files in this tutorial

WEB-INF/resin-web.xmlConfigures the bean with JAXB init
WEB-INF/classes/example/Theater.javaTheater model
WEB-INF/classes/example/Movie.javaMovie model
WEB-INF/classes/example/TestServlet.javaThe servlet implementation.

Configuration

The <bean> configuration sets the movies and theater name.

WEB-INF/resin-web.xml
<web-app xmlns="http://caucho.com/ns/resin">

  <bean jndi-name="beans/theater"
        type="example.Theater">
    <init>
      <name>Balboa Theater</name>
      
      <movie>
        <title>Plan 9 from Outer Space</title>
      </movie>
      
      <movie>
        <title>Snakes on a Plane</title>
	<star>Samuel L Jackson</star>
      </movie>
      
      <movie>
        <title>The Maltese Falcon</title>
	<star>Humphrey Bogart</star>
	<star>Mary Astor</star>
	<star>Peter Lorre</star>
	<star>Sydney Greenstreet</star>
      </movie>
    </init>
  </bean>
      
  <servlet-mapping url-pattern="/test"
                   servlet-class="example.TestServlet"/>
</web-app>

Theater

WEB-INF/classes/example/Theater.java
package example;

import java.util.*;

import javax.xml.bind.annotation.*;

@XmlRootElement
public class Theater
{
  @XmlElement(name="name")
  private String _name;

  @XmlElement(name="movie")
  private ArrayList<Movie> _movieList = new ArrayList<Movie>();
}

Movie

WEB-INF/classes/example/Movie.java
package example;

import java.util.*;

import javax.xml.bind.annotation.*;

@XmlRootElement
public class Movie
{
  @XmlElement(name="title")
  private String _title;
    
  @XmlElement(name="star")
  private ArrayList<String> _starList = new ArrayList<String>();
}

TestServlet

WEB-INF/classes/example/TestServlet.java
package example;

import javax.annotation.Resource;
import javax.servlet.*;

public class TestServlet extends GenericServlet {
  @Resource(name="beans/theater")
  private Theater _theater;

  ...
}

Demo


IoC
IoC
Basic Resource
Copyright © 1998-2006 Caucho Technology, Inc. All rights reserved.
Resin ® is a registered trademark, and Quercustm, Ambertm, and Hessiantm are trademarks of Caucho Technology.