为框架构建自定义Spring配置标记

时间:2011-03-10 16:55:23

标签: java spring

我有一个框架,目前在Spring中需要非常详细的设置:

   <bean id="dpHibernateRemotingAdapter"
            class="org.springframework.flex.core.ManageableComponentFactoryBean">
            <constructor-arg value="org.dphibernate.adapters.RemotingAdapter" />
            <property name="properties">
                    <value>
                            {"dpHibernate" :
                            {
                            "serializerFactory" : "org.dphibernate.serialization.SpringContextSerializerFactory"
                            }
                            }
    </value>
            </property>
    </bean>
    <bean id="dataAccessService" class="org.dphibernate.services.SpringLazyLoadService"
            autowire="constructor">
            <flex:remoting-destination />
    </bean>
    <bean id="dpHibernateSerializer" class="org.dphibernate.serialization.HibernateSerializer"
            scope="prototype">
            <property name="pageSize" value="10" />
    </bean>
    <bean id="dpHibernateDeserializer" class="org.dphibernate.serialization.HibernateDeserializer"
            scope="prototype" />

我想看看提供一个更优雅的配置标签,类似于春天其他地方使用的用户友好标签:

 <context:annotation-config />
 <mvc:annotation-driven />
 <tx:annotation-driven />
 <flex:message-broker/> 

等,

但是,我真的不知道从哪里开始。

这种方法有何用处?这些标签叫什么?什么是他们的基础?

如果有人能指出我在源代码中的类名(理想情况下,<flex:message-broker />,因为这是我项目中最接近的问题),那么我可以从那里开始。我真的不知道从哪里开始!

2 个答案:

答案 0 :(得分:2)

答案 1 :(得分:2)

自定义XML命名空间肯定是可能的(see Appendix D),但根据我的经验,正确的工作是痛苦的。

我强烈建议您使用@Bean-style configuration。这使您可以使用Java来组合bean图,而不是XML。它不仅可以在某些情况下更简洁,它还是类型安全的,并且更容易重复使用。

无论哪种方式,您最终都会编写一些将对象连接在一起的Java。这是一个你想如何揭露它的问题。

相关问题