Matt RaibleMatt Raible is a writer with a passion for software. Connect with him on LinkedIn.

The Angular Mini-Book The Angular Mini-Book is a guide to getting started with Angular. You'll learn how to develop a bare-bones application, test it, and deploy it. Then you'll move on to adding Bootstrap, Angular Material, continuous integration, and authentication.

Spring Boot is a popular framework for building REST APIs. You'll learn how to integrate Angular with Spring Boot and use security best practices like HTTPS and a content security policy.

For book updates, follow @angular_book on Twitter.

The JHipster Mini-Book The JHipster Mini-Book is a guide to getting started with hip technologies today: Angular, Bootstrap, and Spring Boot. All of these frameworks are wrapped up in an easy-to-use project called JHipster.

This book shows you how to build an app with JHipster, and guides you through the plethora of tools, techniques and options you can use. Furthermore, it explains the UI and API building blocks so you understand the underpinnings of your great application.

For book updates, follow @jhipster-book on Twitter.

10+ YEARS


Over 10 years ago, I wrote my first blog post. Since then, I've authored books, had kids, traveled the world, found Trish and blogged about it all.
You searched this site for "beans". 112 entries found.

You can also try this same search on Google.

Webapp Configuration

Jeff Duska has a post tonight on how he handles app-specific configuration settings. His method sounds pretty neat, and hopefully we can combine our methods to come up with a better solution. Here's how I've been doing it.

  1. I have a StartupServlet that reads in an XML file and, using Castor, populates a JavaBean with the XML file's values. Sidenote - I recommend having a StartupServlet in webapps to populate drop-down choices from the database and stuff ArrayLists (of beans) into the ServletContext - works real slick in Struts using the LabelValueBean.
  2. Stuff the JavaBean into the servlet context and get values as needed while running the app.

Jeff's method seems make it easier to retrieve the values, but not to set them. I have a getConfiguration() method in my BaseAction class that I use to get my configuration data:

/**
 * Get the Configuration object from the servlet context
 */
public Configuration getConfiguration(){
    return (Configuration) servlet.getServletContext().getAttribute(
                   Constants.CONFIGURATION);
}

The obvious problem with this is that only subclasses of BaseAction can get the configuration information - therefore, I like Jeff's idea better. However, I'm curious to know how he populates his Registry class. Castor makes it pretty damn easy. Here's the method I use in StartupServlet, where obj is my JavaBean, and xmlFilePath is configured as "/WEB-INF/app-config.xml" in one of StartupServlet's init-parameters.

/**
 * Load our application configuration XML file.
 *
 * @exception Exception if any problem occurs while loading
 */
private synchronized Object loadConfig 
    (
    Object obj, 
    String xmlFilePath
    ) 
throws Exception {

    // attempt to extract the filename, using system file separator
    int index = xmlFilePath.lastIndexOf(Constants.FILE_SEP);

    // no system file separator found in configuration setting
    if (index == -1) {
        // check traditional file separator as used in web app URI's
        index = xmlFilePath.lastIndexOf("/");
        // still no separator, maybe they're just specifying the filename
        if (index == -1) {
            index = 0;
        }
    }

    String xmlFileName = 
        xmlFilePath.substring(index + 1, xmlFilePath.length());
    if (logger.isDebugEnabled()) {
        logger.debug("Looking for '" + xmlFileName + "' in "
                 + Constants.USER_HOME);
    }

    // Acquire an input stream to our configuration file
    InputStream is = null;
    try {
        is = new FileInputStream(Constants.USER_HOME + xmlFileName);
    } catch (FileNotFoundException fnf) {
    
        // No file found in user.home
        if (logger.isDebugEnabled()) {
            logger.debug("File not found at " + Constants.USER_HOME
                + xmlFileName + " - looking at specified path in web.xml.");
        }
        
        // Look for config.xml in WEB-INF
        is = getServletContext().getResourceAsStream(xmlFilePath);
        if (is == null) {
            throw new Exception("Configuration file '"
                + xmlFileName + "' not found in '"
                + Constants.USER_HOME + "', nor at '" + xmlFilePath + "'");
        }
    }

    InputStreamReader reader = new InputStreamReader(is);
    
    // Marshal the configuration object
    obj = Unmarshaller.unmarshal(obj.getClass(), reader);

    // close the InputStream, and the reader
    is.close();
    reader.close();
       
    return obj;
}

I like this method because it can load multiple configuration files, and I already have it written - so the hard part is over ;-) It also makes it easy to configure your app outside of WEB-INF, and changes won't be overwritten when a user upgrades their WAR file or whatnot. I suppose I could use Jeff's method and make my JavaBean into a Singleton and not store it in ServletContext - that'll probably work better than my current scenario.

Posted in Java at Dec 06 2002, 01:24:21 PM MST Add a Comment

The Future of Struts

There's an interesting discussion taking place on the struts-dev mailing list right now. Here's a couple excerpts:

I'd be really interested in your thoughts on the XDoclet work I've done, especially in the Struts Validator realm. I'm generating validation.xml completely, and also all the form bean definitions in our system. I also use XDoclet to process form beans for a one-time starter code generation of a JSP page (templated to our specific look and feel) for a specified form bean, as well as the resource properties that can be used as a starting point for the application resource properties for the field labels. Its amazing amount of generation just on the Struts-side of things, but we use XDoclet for even more than that too. [ Erik Hatcher ]
...
I think it is time to start packaging tools and generators with Struts to help the developer -- either as standalone packages included for convenience, or integrated into the architecture of the package. It would be interesting to explore how XDoclet fits in to this vision. [ Craig McClanahan ]

What exciting times! I can't wait to use XDoclet to generate the validation.xml file for Roller - should be a great learning experience. I don't plan on writing a Struts ActionForm again now that we have XDoclet. Also, I have an update on Roller and XDoclet: Dave found this problem with XDoclet and Castor. It will be fixed in XDoclet 1.2 beta 3. So we wait...

Posted in Java at Nov 20 2002, 09:51:01 AM MST Add a Comment