Caucho maker of Resin Server | Application Server (Java EE Certified) and Web Server


 

Resin Documentation

home company docs 
app server 
 Resin Server | Application Server (Java EE Certified) and Web Server
 

jaxb bean configuration


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> tag creates a singleton component for the Theater, which can be used by any servlet, JSP, JSF, EJB or WebBeans component by using the WebBeans injection annotations..

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

  <bean name="beans/theater"
        class="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.servlet.*;
import javax.webbeans.In;

public class TestServlet extends GenericServlet {
  @In
  private Theater _theater;

  ...
}

Demo


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

Cloud-optimized Resin Server is a Java EE certified Java Application Server, and Web Server, and Distributed Cache Server (Memcached).
Leading companies worldwide with demand for reliability and high performance web applications including SalesForce.com, CNET, DZone and many more are powered by Resin.

home company docs 
app server