Sunday, February 1, 2009

Spring by Example Update

I've been working for a while on an update to Spring by Example. It just happens to be the 1.00 release so I wanted it to be a little bit bigger. It's over a years worth of work at this point and I think it shows how much work I've put into it. I'm happy that it's helping people and will continue to work on it as I have time. I wish I had more. Especially to keep doing more work with the Spring dm Server. Below is a list of the lastest examples posted and I'm working on other ones that I'll hopefully be able to finalize over the next month.

Tuesday, December 9, 2008

Maven generating JAXB with the Fluent API

I thought this was interesting and there wasn't a lot of information on this online. It's using the Maven JAXB plugin to generate JAXB classes with the Fluent API. All the regular methods for getting and setting values are available, but there is also an API to chain together setting and creating classes. Thanks to Steve Berman for the Maven config.

Standard API

PersonResponse personList = new PersonResponse();

Person person = new Person();
person.setId(ID);
person.setFirstName(FIRST_NAME);
person.setLastName(LAST_NAME);

Person person2 = new Person();
person2.setId(SECOND_ID);
person2.setFirstName(SECOND_FIRST_NAME);
person2.setLastName(SECOND_LAST_NAME);

personList.getPerson().add(person);
personList.getPerson().add(person2);


Fluent API

PersonResponse personList = new PersonResponse().withPerson(
    new Person().withId(ID).withFirstName(FIRST_NAME).withLastName(LAST_NAME),
    new Person().withId(SECOND_ID).withFirstName(SECOND_FIRST_NAME).withLastName(SECOND_LAST_NAME));


Inside the build element's plugins section, this can be added to generate JAXB beans with the Fluent API.

<plugin>
    <groupId>org.jvnet.jaxb2.maven2</groupId>
    <artifactId>maven-jaxb2-plugin</artifactId>
    <configuration>
        <extension>true</extension>
        <args>
            <arg>-Xfluent-api</arg>
        </args>
        <schemaDirectory>src/main/resources</schemaDirectory>
        <plugins>
            <plugin>
                <groupId>net.java.dev.jaxb2-commons</groupId>
                <artifactId>jaxb-fluent-api</artifactId>
                <version>2.1.8</version>
            </plugin>
        </plugins>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
        </execution>
    </executions>
</plugin>

<repositories>
    <repository>
        <id>maven2-repository.dev.java.net</id>
        <name>Java.net Maven 2 Repository</name>
        <url>http://download.java.net/maven/2</url>
    </repository>
</repositories>

Friday, December 5, 2008

Spring by Example Wins

I was going to really try to get back into working on the book, but I think I realistically don't have the time. I did make a small update to Spring In-depth, In Context before SpringOne started, but I was thinking about how Spring 3.0 is coming out soon so I would need to go through everything again. Posting examples on Spring by Example is less effort since each example is more or less standalone and I'm primarily writing up something specifically on the example. Instead of trying to explain the subject completely, which involves a lot more research and effort. Maybe one day I'll try to get back into working on it, but I actually think hands on examples are probably more valuable. At least that what I always like to see. I typically just want to get going on a project and I'll learn all the nuances of the technology as I go. Possibly the preface and intro from the book can become part of the Spring by Example documentation at some point.

Based on this decision I moved the work I had done for the book to Spring by Example.

Tuesday, December 2, 2008

SpringOne Americas 2008 Presentation

SpringOne has been really interesting so far. Rossen Stoyanchev gave a really excellent presentation on all the nuances and best practices for using Spring MVC Annotations. I'll need to update all my web examples, because there's at least one thing if not more that could be done more elegantly. Like using the @ModelAttribute on a method to populate the model for a form instead of using a dummy method just for a create (so the form has an instance to bind to).

My presentation on GWT & Dojo Cometd with Spring Bayeux is tomorrow morning. I've put a lot of work into the presentation, writing up what I could for Spring In Depth, In Context, and getting the examples cleaned up as much as possible and checked into Subversion. Hopefully the presentation will go well and everyone will find it interesting.

Spring by Example & 'Spring In-depth, In Context'

I've made updates to both sites. Spring by Example doesn't have anything too major, but the last site release updated the Spring by Example Web Module to version 1.1.1. For Spring In-depth, In Context, I finally had time to get the Chat and Trade Monitor examples I made for my SpringOne presentation posted and written up for Jetty. The examples are checked in except for the Trade Monitor example running an embedded Jetty in Tomcat. This is the same as the Trade Monitor that runs under Jetty, was just to show that you could still use Jetty's Bayeux implementation even if you were on Tomcat.

Also I finally had time to post a simple Spring dm Server example showing side-by-side versioning. It has a version 1.0 and 1.1 of a message service. The version 1.0 uses Commons Lang 2.1.0 and version 1.1 uses Commons Lang 2.4.0. There is a web module that just displays the data and you can switch back and forth between the two different message services at runtime. I'll work on this section more to add screen shots and a more detailed explanation of things, but I wanted to get what was ready posted.


Wednesday, November 26, 2008

Maven & No Commons Logging

Maven includes Commons Logging by default, which isn't what you really want if you'd like to use SLF4J for your logging facade. A nice solution to fake out Maven was written at this blog. Basically you have a fake version 99.0 as an empty jar named the same as Commons Logging so it's downloaded instead.

I noticed builds were running really slow and it seems that he Maven repository (http://no-commons-logging.zapto.org/mvn2) has been down for days. As a temporary solution I've put the no Commons Logging jars into the Spring by Example repo and put a mirror entry into my settings.xml.

It would be nice if Maven just had a way to do global excludes if you don't want a jar no matter what transitive dependencies are resolved.


~/.m2/settings.xml
<settings>
  <mirrors>
    <mirror>
      <id>no-commons-logging</id>
      <name>No Commons Logging</name>
      <url>http://www.springbyexample.org/maven/repo</url>
      <mirrorof>no-commons-logging</mirrorof>
    </mirror>
  </mirrors>
</settings>

Wednesday, November 19, 2008

SpringOne Americas 2008

I'm presenting this year at SpringOne Americas 2008. I'm really looking forward to it and have been working on examples and the slides for the conference. That's why I haven't posted much lately. I'll be presenting a Case Study of my investigation of GWT, Comet, and Bayeux integration with Spring for developing a trade monitor. I'll be posting the examples soon and will also write about them, but the slides will just be for those that the attend the conference. It should be a very good conference. I really enjoyed it last year. It's one of the more technical conferences I've been to.