FREE Subscription to Dr. Dobb’s Digest: Same Great Content, New Digital Edition
Site Archive (Complete)
Java Blog: JBullet and Resource Injection
Java
SWAINE'S CAFE

Black. No Sugar. Extra Caffeine.

by Mike Swaine
ERIC BRUNO'S BLOG

Java: The Daily Grind.

by Eric Bruno
June 14, 2006

JBullet and Resource Injection

Have you checked out the JBullet web framework?

You can download release 1.0 of JBullet at https://jbullet-web.dev.java.net, and you can contribute to the next release. JBullet is a simple MVC-based framework for Java web applications that’s straightforward and simple. It doesn’t use XML for configuration, and doesn’t require you to learn anything new. You simply write your class code, use the provided base classes and tag library, and you’ll soon discover why it’s named JBullet -- it's fast and to the point.

For example, the following code (when deployed in a Servlet container such as Tomcat), displays a simple "Hello World" web page:

import org.jbullet.controller.BaseController;
public class HelloController extends BaseController
{
    public void index()
    {
        renderText("Hello World");
    }
    public void eric()
    {
        renderText("Hello from Eric!!!!");
    }
}

In this example (Tomcat’s web.xml configuration not shown), navigating your browser to the URL http://localhost/HelloController displays the text "Hello World" on the page. However, navigating to http://localhost/HelloController/eric invokes the eric() method of the class HelloController, and results in the text "Hello from Eric!!!!" on the page.

Resource Injection and Java EE 5

Annotations in Java EE 5 enable the injection of resources, services, and notifications in your enterprise applications, making it easier and simpler to develop applications that access databases or web services. Resource injection eliminates the need to write boiler-plate code, or messy XML configuration files. For example, the following sample code’s use of annotations informs the container to inject the needed resource automatically (no explicit JNDI lookup is needed):

private @Resource DataSource catalogDS;
public getProductsByCategory() {
    // Get a connection and execute the query.
    Connection conn = catalogDS.getConnection();
    ...
} 

To read more about Java EE 5 and resource injection, read this article recently posted on Sun’s Java EE site.

Posted by Eric Bruno at 05:01 AM  Permalink




 
INFO-LINK