Grails
  1. Grails
  2. GRAILS-31

Support Scripting of the Spring App Context

    Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 0.1
    • Fix Version/s: 0.4
    • Component/s: Configuration
    • Labels:
      None

      Description

      Support scripting of the Spring application context using Groovy meta programming. At the moment all current implementations of this don't take advantage of the groovy meta facility, hence end up with a robust syntax rather than somethingl ike this:

      import org.apache.commons.dbcp.*
      import org.springframework.orm.hibernate3.*

      class ApplicationContext {
      @Property beans = {
      def ds = dataSource('destroy-method':'close',BasicDataSource.class)

      { driverClassName("com.mysql.jdbc.Drive") url("jdbc:mysql://localhost/testDb") username("root") password("admin") }

      def sf = sessionFactory(LocalSessionFactoryBean.class)

      { configurationClass("org.hibernate.cfg.AnnotationConfiguration") hibernateProperties ['hibernate.dialect' : 'org.hibernate.dialect.MySQLDialect'] dataSource(ds) }


      }
      }

      This is the equivalent of the Spring xml:

      <beans>
      <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
      <property name="driverClassName">
      <value>com.mysql.jdbc.Driver</value>
      </property>
      <property name="url">
      <value>jdbc:mysql://localhost/testDb</value>
      </property>
      <property name="username">
      <value>root</value>
      </property>
      <property name="password">
      <value>admin</value>
      </property>
      </bean>
      <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
      <property name="configurationClass">
      <value>org.hibernate.cfg.AnnotationConfiguration</value>
      </property>
      <property name="hibernateProperties">
      <props>
      <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
      <prop key="hibernate.hbm2ddl.auto">update</prop>
      </props>
      </property>
      <property name="dataSource">
      <ref bean="dataSource" />
      </property>
      </bean>
      </beans>

        Issue Links

          Activity

          Hide
          Graeme Rocher added a comment -

          The above proposal is deprecated in favour of the proposal outlined here:

          http://grails.org/The+Plug-in+System

          Show
          Graeme Rocher added a comment - The above proposal is deprecated in favour of the proposal outlined here: http://grails.org/The+Plug-in+System
          Hide
          Graeme Rocher added a comment -

          Done. Syntax is different to the above. Documentation to follow

          Show
          Graeme Rocher added a comment - Done. Syntax is different to the above. Documentation to follow

            People

            • Assignee:
              Graeme Rocher
              Reporter:
              Graeme Rocher
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development