Grails 将Xml配置转换为resource.groovy

Grails 将Xml配置转换为resource.groovy,grails,groovy,Grails,Groovy,我是grails新手,我想将xml配置转换为resource.groovy。但是xml中有名称空间。我不想在这里重复配置。应该有一个配置是resource.groovy 我的xml是 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schem

我是grails新手,我想将xml配置转换为resource.groovy。但是xml中有名称空间。我不想在这里重复配置。应该有一个配置是resource.groovy

我的xml是

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
    xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd
http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/data/neo4j
            http://www.springframework.org/schema/data/neo4j/spring-neo4j.xsd">

            <context:component-scan base-package="neo4j"></context:component-scan>


    <util:map id="config">
        <entry key="ha.server_id" value="2" />
        <entry key="ha.initial_hosts" value="127.0.0.1:5001,127.0.0.1:5002" />
        <!-- put in more config parameters here, http://docs.neo4j.org/chunked/stable/ha-configuration.html -->
    </util:map>
    <bean id="graphDbFactory"
        class="org.neo4j.graphdb.factory.HighlyAvailableGraphDatabaseFactory" />
    <bean id="graphDbBuilder" factory-bean="graphDbFactory"
        factory-method="newHighlyAvailableDatabaseBuilder">
        <constructor-arg value="/home/alok/Desktop/data4" />
    </bean>
    <bean id="graphDbBuilderFinal" factory-bean="graphDbBuilder"
        factory-method="setConfig">
        <constructor-arg ref="config" />
    </bean>
    <bean id="graphDatabaseService" factory-bean="graphDbBuilderFinal"
        factory-method="newGraphDatabase" destroy-method="shutdown" />

    <neo4j:config graphDatabaseService="graphDatabaseService"   base-package="neo4j"/>
    <neo4j:repositories base-package="neo4j" />

</beans>

我想知道如何处理名称空间和构造函数参数,这里确实有两个问题,但让我们来回答这两个问题

如何在resources.groovy中使用名称空间

以下是如何:

// resources.groovy
beans {
  xmlns neo4j:"http://www.springframework.org/schema/data/neo4j"
  xmlns context:"http://www.springframework.org/schema/context"
  ... // and so on.
  // neo4j.repositories
}
// resources.groovy
beans {
  someBean(
    SomeBeanClass, 
    'stringArg1', 
    ['listOfStringsArg2', 'listOfStringArg2-a'],
    ref('someOtherBeanAsArg3')
  )
}
如何在resources.groovy中使用构造函数参数

以下是如何:

// resources.groovy
beans {
  xmlns neo4j:"http://www.springframework.org/schema/data/neo4j"
  xmlns context:"http://www.springframework.org/schema/context"
  ... // and so on.
  // neo4j.repositories
}
// resources.groovy
beans {
  someBean(
    SomeBeanClass, 
    'stringArg1', 
    ['listOfStringsArg2', 'listOfStringArg2-a'],
    ref('someOtherBeanAsArg3')
  )
}

这里确实有两个问题,但让我们同时回答这两个问题

如何在resources.groovy中使用名称空间

以下是如何:

// resources.groovy
beans {
  xmlns neo4j:"http://www.springframework.org/schema/data/neo4j"
  xmlns context:"http://www.springframework.org/schema/context"
  ... // and so on.
  // neo4j.repositories
}
// resources.groovy
beans {
  someBean(
    SomeBeanClass, 
    'stringArg1', 
    ['listOfStringsArg2', 'listOfStringArg2-a'],
    ref('someOtherBeanAsArg3')
  )
}
如何在resources.groovy中使用构造函数参数

以下是如何:

// resources.groovy
beans {
  xmlns neo4j:"http://www.springframework.org/schema/data/neo4j"
  xmlns context:"http://www.springframework.org/schema/context"
  ... // and so on.
  // neo4j.repositories
}
// resources.groovy
beans {
  someBean(
    SomeBeanClass, 
    'stringArg1', 
    ['listOfStringsArg2', 'listOfStringArg2-a'],
    ref('someOtherBeanAsArg3')
  )
}

您知道,您可以将其作为resource.xml复制到resource.groovy?是的,我必须使用resource.groovy进行配置,使用groovy模式您知道,您可以将其作为resource.xml复制到resource.groovy旁边。groovy?是的,我必须使用resource.groovy进行配置,使用groovy模式谢谢,但处理具有多个URL的架构位置时存在问题。多个URL?为什么呢这里列出的所有模式都只有一个。好的,如何处理模式位置。xsi:schemaLocation=>我将更新答案,告诉您可以添加多个,并且在使用bean builder DSL时不需要定义schemaLocation。很抱歉,这里还有一个愚蠢的问题,在xml中,我们将工厂方法传递给一些参数,它返回object。那么在resource.groovy中,情况会怎样呢?谢谢,但是在处理具有多个URL的模式位置时存在问题。多个URL?为什么呢这里列出的所有模式都只有一个。好的,如何处理模式位置。xsi:schemaLocation=>我将更新答案,告诉您可以添加多个,并且在使用bean builder DSL时不需要定义schemaLocation。很抱歉,这里还有一个愚蠢的问题,在xml中,我们将工厂方法传递给一些参数,它返回object。那么在resource.groovy中,情况会如何呢?