在Grails中运行时,Spring别名不可用

在Grails中运行时,Spring别名不可用,spring,grails,Spring,Grails,我对Grails中的Spring别名有问题。我有一个library.jar文件,其中包含的类和Spring配置没有按预期工作。当我从一个标准(没有Grails)Java应用程序导入它们时,它确实像预期的那样工作 当前配置包含以下内容 <bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller"> <property name="contextPath" value="uk.co.com

我对Grails中的Spring别名有问题。我有一个library.jar文件,其中包含的类和Spring配置没有按预期工作。当我从一个标准(没有Grails)Java应用程序导入它们时,它确实像预期的那样工作

当前配置包含以下内容

<bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
   <property name="contextPath" value="uk.co.company.package"/>
</bean>

<alias name="marshaller" alias="unmarshaller"/>
将配置更改为以下设置,然后使其按预期工作

<bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
   <property name="contextPath" value="uk.co.company.package"/>
</bean>
<bean id="unmarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
   <property name="contextPath" value="uk.co.company.package"/>
</bean>

正在导入和读取配置。由于某些原因,当我尝试使用别名时,它不可用。这是什么原因


这是Grails 1.3.7和Spring 3.0.5的一部分。

此链接可能对您有所帮助:


这里提到,别名至少在resources.xml中声明时不起作用。这篇文章还提到了一种通过编程声明别名的方法。但这篇文章似乎是很久以前写的,不确定它与Grails1.3.7有多相关。

我也看到了这个问题。您可以通过在Grails resources.xml中或在我的插件doWithSpring闭包中定义别名来解决这个问题:

springConfig.addAlias "aliasName", "beanName"

我希望importBeans也能导入别名

我在我的提问前的谷歌搜索中发现了这一点,第一条评论将其链接到很久以前修复的Jira问题。我们就是这么做的。这不是我所希望的解决方案,但它是有效的。
springConfig.addAlias "aliasName", "beanName"