The Artima Developer Community
Sponsored Link

Java Buzz Forum
Consilidating Spring Config with Groovy

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
dion

Posts: 5028
Nickname: dion
Registered: Feb, 2003

Dion Almaer is the Editor-in-Chief for TheServerSide.com, and is an enterprise Java evangelist
Consilidating Spring Config with Groovy Posted: Sep 27, 2004 6:51 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by dion.
Original Post: Consilidating Spring Config with Groovy
Feed Title: techno.blog(Dion)
Feed URL: http://feeds.feedburner.com/dion
Feed Description: blogging about life the universe and everything tech
Latest Java Buzz Posts
Latest Java Buzz Posts by dion
Latest Posts From techno.blog(Dion)

Advertisement
When working with Spring, have you noticed yourself doing a lil copy/paste in the applicationContext.xml? I have seen a fair share on different projects. For example, you wrap your DAO model with the transaction proxy, and the config is the same for each. One of them looks something like this: <bean id="UserDAO" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="transactionManager"> <ref local="transactionManager"/> </property> <property name="target"> <ref local="userDAOTarget"/> </property> <property name="transactionAttributes"> <props> <prop key="add*">PROPAGATION_REQUIRED</prop> <prop key="set*">PROPAGATION_REQUIRED</prop> <prop key="update*">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <bean id="userDAOTarget" class="com.foo.dao.UserDAOImpl"> <property name="sessionFactory"> <ref local="sessionFactory"/> </property> </bean> Instead of duplicating the code for every object in the model it would be great if there was Groovy support so you could do something like this: modelBeans = ['User', 'Auction', 'Bid', ..] txRequiredMethods = ['add*', 'set*', 'update*'] modelBeans.each { | beanName | builder = new SpringMarkupBuilder() markup = { bean(id="${beanName}DAO", class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean") { property(name: 'transactionManager') { ref(local: 'transactionManager') } property(name: 'target') { ref(local: "${beanName}DAOTarget"); } property(name: 'transactionAttributes') { props { txRequiredMethods.each { | txMethod | prop(key: txMethod, value: 'PROPAGATION_REQUIRED') } } } } bean(id="${beanName}DAOTarget", class="com.foo.dao.${beanName}DAOImpl") { property(name: 'sessionFactory') { ref(local: "sessionFactory"); } } } } Of course, many other solutions would help out here.

Read: Consilidating Spring Config with Groovy

Topic: Snap Into a Slim Jim! Previous Topic   Next Topic Topic: The Wonderful Thing About Standards...

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use