更新:
我已经安装了grails 2.0
我有两个Domain classesApplicationConfiguration和City,
ApplicationConfiguration存储默认字段及其值
City将访问ApplicationConfiguration值
class ApplicationConfiguration {
String myDefaultField
String value
static getMyDefaultCity(){
def city_id = ApplicationConfiguration.findByMyDefaultField('city') .id
def cityName = ApplicationConfiguration.get(city_id ).value
}
}
Class City{
def ApplicationConfiguration
String city = ApplicationConfiguration.getMyDefaultCity()
}
基本上我无法从域和服务中访问GORM方法,例如 1)executeQuery() 2)找到*()
我收到如下错误
... 5 more
Caused by: org.hibernate.InstantiationException: could not instantiate test objectCity
... 5 more
Caused by: java.lang.reflect.InvocationTargetException
... 5 more
Caused by: groovy.lang.MissingMethodException: No signature of method: ApplicationConfiguration.findByMyDefaultFie
ld() is applicable for argument types: (java.lang.String) values: [city]
at ApplicationConfiguration.getMyDefaultCity(ApplicationConfiguration.groovy:63)
at City.<init>(City.groovy:28)
当我在我的控制器中执行ApplicationConfiguration.findByMyDefaultField('city')
时,它工作正常,可以在控制器中访问GORM方法
重现错误的测试用例是
1) Create a project using grails project wizard
2) Create two domain classes ApplicationConfiguration(String myDefaultField, String value) and City(String city)
3) Do generate-all for ApplicationConfiguration
4) Now add this "getMyDefaultCity()" with the definition method as shown above
5) Initialize the filed city in City domain class "String city = ApplicationConfiguration.getMyDefaultCity()"
6) Restart the application
答案 0 :(得分:0)
也许这个问题可能对您有用:Adding business logic to a domain class using a getter style method name
您是否使用过该方法的瞬态声明?