Grails 我可以在groovy域中注入依赖项吗?
在我的项目中,我使用两个数据库,两个数据库中的列名都不同。所以我在配置文件中定义了一个标志,并在域中注入了依赖项 示例:--> 是否有其他方法根据数据库定义列名 我在执行此代码时收到错误。 错误是,Grails 我可以在groovy域中注入依赖项吗?,grails,gorm,Grails,Gorm,在我的项目中,我使用两个数据库,两个数据库中的列名都不同。所以我在配置文件中定义了一个标志,并在域中注入了依赖项 示例:--> 是否有其他方法根据数据库定义列名 我在执行此代码时收到错误。 错误是, “计算域MRAffiliate的ORM映射块时出错没有这样的属性:grailsApplication for class:org.codehaus.groovy.grails.ORM.hibernate.cfg.HibernateMappingBuilder”试试Holders.grailsAppl
“计算域MRAffiliate的ORM映射块时出错没有这样的属性:grailsApplication for class:org.codehaus.groovy.grails.ORM.hibernate.cfg.HibernateMappingBuilder”试试Holders.grailsApplication.config.xxx——看看哪个使用映射块中的配置。试试Holders.grailsApplication.config.xxx——看看哪个使用映射块中的配置。@Szymon这是哪个grails版本?grails版本:2.4.4您正在尝试访问一个实例变量(
grailsApplication
)从静态上下文(映射closure`)中访问。您无法从静态上下文访问任何实例状态。该语言不允许,因为它是非感官的。@Szymon这是哪个grails版本?grails版本:2.4.4您正在尝试访问实例变量(<代码> GravsApdioAs/<代码>)从静态上下文(<代码>映射< /代码>闭包】)。不能从静态上下文访问任何实例状态。语言不允许,因为它是无意义的。很好地知道它为您工作。请考虑接受答案:很高兴知道它为你工作…请考虑接受答案:
class MRAffiliate {
transient def grailsApplication;
String companyName;
String annotations;
static mapping = {
table name: "affiliati"//, schema: "public"
id generator:'sequence', params:[sequence:'affiliati_seq']
id column: "id"//, sqlType: "int4";
if (grailsApplication.config.com.dogmasystems.postgres==true){
companyName column: "ragione_sociale";
} else {
companyName column: "ragione_sociale", sqlType: "string";
}
if (grailsApplication.config.com.dogmasystems.postgres==true){
annotations column: "annotazioni";
} else {
annotations column: "annotazioni", sqlType: "string";
}
version false;
}
}