Archive

Archive for the ‘Spring’ Category

Spring 2.x IOC exploring

November 18, 2007 Leave a comment

OK, Lets see how the IOC (DI) module move forward in the spring 2.x version.

  1. XML configuration extensions.

    I would say this enhancement make the third-party library, which build on spring’s IOC container, a lot of easier for the configuration. Such as Apache CXF, Apache Activemq and so on. Personally, I would consider this is a big improvement for the configuration, and integration with other libraries.
    Adding a custom xml configuration typically has below four steps:

    • Authoring an xml schema to describe your custom element(s).
    • Coding a custom NameSpaceHandler implementation.
    • Coding one or more BeanDefinitionParser implementation. (This is the real job that need to be done. populate the data from xml file).
    • Registering the above artifact with spring.

    The most real job is parsing the xml in the BeanDefinitionParser class, and get the data from xml to bean.

    The spring’s registering way is an inspiration of how we can register the stuff modularly, instead of putting all of configuration file in one center place, we can split them in its own module, but with the same relative path, such as /META-INF/spring/spring.handlers for spring’s example.

  2. New Bean scopes.
    In the Spring1.x IOC module, it just has two scope:the singleton and non-singleton, it is way too coarse-grain. In the 2.x version, it adds more scopes, like Session scope, Request scope etc..it also has custom scope.
  3. Spring Java config.
    To be specific, this is introduced by the spring2.5.. I am gonna try this later and give it a comparison with Guice in next couple entries..

Reference
1. Spring 2.x extensible xml explanation
2. spring-components-xml-configuration-on-steroids (example)
3. Spring2.o Intro (Posted at InfoQ)
4. How CXF configuration works
5. Spring Java config reference

Categories: Java, Spring

Is it a bad idea to reply on Spring too much?

November 17, 2007 Leave a comment

Since spring is more and more powerful & popular, to some extent, it becomes the de facto JEE application’s infrastructure, so a lot of projects in the open source area(Apache CXF, Apache Servicemix …) use spring as its basic configuration & bean management… some of my colleagues said it was a bad idea that we rely on spring too much. I don’t so, reasons are:

  1. Spring is open source, we can see how it gets the job done, we know how it works, we can modify it as what we want.
  2. Take Apache CXF for example, since now a lot of people are using spring, it is not a good idea to create another XSD or DTD to ask people to learn for configuration, always remember people are lazy, we need to reduce the learning curve. Since spring did a good job, at least, if you want to write a new one, you need to specify where the spring configuration can’t meet your requirement..
  3. Some people think relying on spring too much, maybe one day, we will lose our place, since interface21 people (which create and provide support for spring) will take over our product… I don’t agree with it, spring is good at one place, but it doesn’t mean that they are good at everything, or they do not have time to take everything… look how eclipse and those eclipse plug-ins work together..

All in all, I don’t think rely on spring too much is a bad thing, instead, I think we need to adopt those good libraries, not to write a new one simply because we are afraid that we might lose our place.. remember, open source software means you can see how codes work, you can change them.. Successful people always stand on a giant…

Categories: Spring, Thoughts

Spring 1.2.x IOC exploring

November 17, 2007 Leave a comment

Spring uses bean factory to manage the application beans. what we most uses is using the xml config file to define the beans dependency and initializations..

Here I do not want to elaborate the whole config thing, there are a lot of material in the Internet and Reference, which did a better job than me, I just want to list some features that you might not use that often, and might don’t know it yet.

  1. Bean’s auto-wiring. (By Name, By Type, Construcotor, auto-detect).. but here I think it is better for us to wire beans explicitly. But if you are a COC fan, then you might be like this functionality.
  2. Bean creation by static factory method or by instance factory method. In most of cases, we are using bean creation by constructor, but for legacy codes integration, we might need the other two options.
  3. Method Injection, by using look-up method Injection & arbitrary method replacement.
  4. “depends-on” attribute, in case there is a bean rely on other bean’s initialization.
  5. Lifecycle interfaces. (InitializatingBean, DisposableBean) or using init-method, destory-method in config file.
  6. Aware-suffix interface, such as BeanFactoryAware, ApplicationContextAware… if you want to get the BeanFactory or ApplicationContext object in your bean, such as publish events in the applicationContext, you can implement *Aware interface to get it. Spring will populate the context to your bean.
  7. FactoryBean. This one is quite easy to get confused by the BeanFactory at first glance. They are totally different.. BeanFactory is managing beans.. FactoryBean just take charges of creating a bean. Remember in most cases, we are creating a bean via constructor..what if we want to create a proxy class, which target is the bean’s instance.. Then implements the FactoryBean’s interface to do that. (commonly, it is used in the spring’s library itself, such as AOP proxy class, JndiObjectFactoryBean and so on.

Reference:
1. Spring 1.2.x Reference
2. <<Expert one-on-one Design and Development>> chapter 11.
3. Java Passion Free course

Categories: Java, Spring

IMS rolled out its 0.1 version

November 13, 2007 Leave a comment

I created a little project at Google Code, it rolled out its 0.1 version in 5 Nov 2007.. In this release, it demonstrates below functionalities (copied from release note)..

ims-core module

  1. Using JAXWS + JAXB (CXF runtime) to publish web service.
  2. Using Spring acegi as web service authorization.
  3. Using ws-security (plain password) as authentication.
  4. Using Spring AOP transaction.
  5. Using DBUnit to do the dao unit test.
  6. Using easymock to do the service layer unit test.
  7. Using cxf local transport to do the web service unit test.

ims-web module

  1. Using CXF wsdl2java (codegen tool) to generate the stub.
  2. Using JAXWS customization to use the java.util.Date instead of XMLGregorianCalendar.
  3. Using JAXWS + JAXB (CXF runtime) to access the web service.
  4. Using Spring acegi web application filter and Jcaptcha as security implementation.
  5. Using div + css as layout design implementation.

You can download the source code from here, since its war size is about 20M, I don’t provide it in the website, you need to refer to the README.txt in the source code to build it, it is quite straightforward to get it working.. (actually you just need to set up database manually, and then update the database connection config file appropriately).

I’ve also created some tasks for 0.2 release or future in the issue page, if you want to join this project, drop me a mail, (or add a comment here), I would add you as a commiter.

Categories: CXF, Java, Spring