Skip to content

Instantly share code, notes, and snippets.

@berngp
Created May 3, 2011 19:19
Show Gist options
  • Save berngp/954008 to your computer and use it in GitHub Desktop.
Save berngp/954008 to your computer and use it in GitHub Desktop.
Splitting SpringBeans files in Grails (Examples with JMS and JMX Bean files)
//grails-app/conf/JMSSpringBeans.groovy
import grails.util.Environment
import org.apache.activemq.spring.ActiveMQConnectionFactory
import org.springframework.jms.connection.SingleConnectionFactory
import grails.util.Environment
import org.apache.activemq.spring.ActiveMQConnectionFactory
import org.springframework.jms.connection.SingleConnectionFactory
beans {
xmlns amq: "http://activemq.apache.org/schema/core"
amq.broker(xmlns: "http://activemq.apache.org/schema/core",
brokerName: "localhost",
dataDirectory: "target/localhost-activemq-data") {
amq.transportConnectors{
amq.transportConnector(name:"vm", uri:"vm://localhost" )
}
}
defaultConnectionFactory(ActiveMQConnectionFactory) {
brokerURL = 'vm://localhost?create=false&waitForStart=100'
}
jmsConnectionFactory(SingleConnectionFactory) {
targetConnectionFactory = ref('defaultConnectionFactory')
}
/**
* The {@code jmsExternalsConnectionFactory} and {@code jmsInstancesConnectionFactory} are connection
* factories that might potentially be linked to an external MQ provider such as ActiveMQ, Tibco EMS, HornetMQ, etc.
* <pre>
* jmsExternalsConnectionFactory( TheClass ) {
* url = 'theurl'
* username = 'ausername'
* password = 'apassword'
* }
* jmsInstancesConnectionFactory( TheClass ) {
* url = 'theurl'
* username = 'ausername'
* password = 'apassword'
* }
* </pre>
*/
if (Environment.current == Environment.TEST || Environment.current == Environment.DEVELOPMENT ) {
jmsExternalsConnectionFactory(SingleConnectionFactory) {
targetConnectionFactory = ref('defaultConnectionFactory')
}
jmsInstancesConnectionFactory(SingleConnectionFactory) {
targetConnectionFactory = ref('defaultConnectionFactory')
}
}
}
//grails-app/conf/JMXSpringBeans.groovy
import org.springframework.jmx.export.MBeanExporter
import org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource
import org.springframework.jmx.export.annotation.AnnotationMBeanExporter
import org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler
import org.springframework.jmx.export.naming.MetadataNamingStrategy
import org.springframework.jmx.support.MBeanRegistrationSupport
beans = {
annotationJmxAttributeSource(AnnotationJmxAttributeSource)
jmxAnnotationsExporter(AnnotationMBeanExporter) {
server = { org.springframework.jmx.support.MBeanServerFactoryBean sfb ->
locateExistingServerIfPossible = true
}
autodetect = true
autodetectMode = MBeanExporter.AUTODETECT_ASSEMBLER
registrationBehavior = MBeanRegistrationSupport.REGISTRATION_IGNORE_EXISTING
assembler = { MetadataMBeanInfoAssembler mbeanIA ->
attributeSource = ref(annotationJmxAttributeSource)
}
namingStrategy = { MetadataNamingStrategy ns ->
attributeSource = ref(annotationJmxAttributeSource)
}
}
}
//grails-app/conf/resources.groovy
beans = {
importBeans 'classpath*:/spring/*.groovy'
}
//scripts/_Events.groovy
eventCompileEnd = {
ant.copy(todir:"${classesDirPath}/spring"){
fileset( dir:"grails-app/conf/spring" ){
include(name:"*.groovy")
exclude(name:"resources.groovy")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment