Announcement Announcement Module
Collapse
No announcement yet.
SpringX: use Spring without biz bean config Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • SpringX: use Spring without biz bean config

    What's SpringX ?
    SpringX is agile framework for using Spring. It provides zero-bean config mechanism eliminating hundreds business bean config in enterprise dev.

    What features does SpringX framework have?
    Feature List:
    * . Dependency Injection without XML and annotation of biz bean;
    * . Strong type bean creation;
    * . Interface Injection, wildcard surrport.
    * . Much simpler AutoProxyCreator config bean for AOP.

    1. SpringX Code sample - autowire and strong type getting bean.
    Given a business bean OrderService, it's dependent on OrderDAO,UserService.

    Code:
      package org.bamboo.springx.test.demo.service;
         public class OrderService {
                private UserService userService;
                private OrderDAO orderDAO;
                public void setOrderDAO(OrderDAO orderDAO) {
                        this.orderDAO = orderDAO;
                }
    
                public void setUserService(UserService userService) {
                        this.userService = userService;
                }
                //... other code
            }
    Let's think for a while. How does Spring 2.0.x or 2.5+ support DI?
    In Spring 2.0.x, we should use XML config such as
    Code:
    <bean id="orderService" ../>.
    But it's tedious in large scale enterprise application.
    In Spring 2.5+ , annotations should be written on bean classes such as @Component,@Autowired etc. But's it's ugly, and impossible for integration of legacy system with Spring .

    Then is there any agile way?
    In SpringX framework, biz code may be like below
    Code:
       
      import org.bamboo.springx.*;
          //instead of weak type get bean:  context.getBean("orderService");
              
            ApplicationContext applicationContext = new ClassPathXmlApplicationContext( "applicationContext.xml" );
                BeanFactory beanFactory = BeanFactory.wrapApplicationContext( applicationContext );
    
               OrderService orderService = (OrderService) beanFactory.createBean(OrderService.class);
               orderService.createOrder("AA001");  //biz operation
               orderService.deleteOrder("AA002");  //biz operation
    There'are 2 differences, the creation of context and bean getting.
    The beanFactory.createBean( class ) method is strongly recommended, because it's strong type,but not a bean id string. This is very useful in JEE dev. You doesn't need to worry about wrong spell, especially in refactoring.


    2. SpringX config.
    - wildcard config for all biz beans.

    But how does SpringX autowire orderDAO,userService to OrderService? The key is DynamicAutoWireInjector bean and its 'autowireFilters' property. It uses a wildcard string to indicate which beans need to be auto injected.
    applicationContext.xml

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans>    
            <bean id="org.bamboo.springx.DynamicAutoWireInjector" class="org.bamboo.springx.DynamicAutoWireInjector">
                    <property name="autowireFilters">
                            <list>
                                    <value>org.bamboo.springx.test.*.*Service</value> 
                                    <value>org.bamboo.springx.test.*.*DAO</value>     
                            </list>
                    </property>
            </bean>

    But if OrderDAO is an interface, impl class is OrderImpl, how does SpringX know which bean to be created and injected?
    SpringX provided Interface2ImplMapper to do this. It uses a wildcard interface to impl class mapping to indicate the rule, call Interface Injection.

    Code:
            <bean id="org.bamboo.springx.Interface2ImplMapper" class="org.bamboo.springx.Interface2ImplMapper">
                    <property name="interfaceClassMapping">                
                            <props>                       
                                    <prop key="org.bamboo.*.dao.*DAO">org.bamboo.*.dao.*DAOImpl</prop>
                                    <prop key="org.bamboo.*.service.*Service">org.bamboo.*.service.*ServiceImpl</prop>
                            </props>
                    </property>
            </bean>
    So neither XML config nor annotaion( @Component, @Autowired etc) are required anymore. SpringX can help you autowire dependent bean.

    On the whole, we can see the Code by Convertion is conformed very well in SpringX . In a large scale applicatin such as telecom, B2B, finance, CBC spec is very important and useful.

    The lastest version is 1.2.2. You can download SpringX on google code: SpringX Framework
    Last edited by raymond.kk.he; Nov 2nd, 2009, 05:18 AM. Reason: modify features
Working...
X