将命令注入命名空间的Controller始终解析为最高版本的服务,无论Controller中声明的命名空间如何。
package com.vertest.v1
class VertestController {
static namespace = 'v1'
def vertestService
def agateSer() {
render vertestService.agate()
}
}
package com.vertest.v1
class VertestService {
def agate() {
this.getClass().getName()
}
}
package com.vertest.v2
class VertestController {
static namespace = 'v2'
def vertestService
def agateSer() {
render vertestService.agate()
}
}
package com.vertest.v2
class VertestService {
def agate() {
this.getClass().getName()
}
}
UrlMappings.groovy
"/v1/agateservice"(controller:"vertest", action:"agateSer", namespace:"v1")
"/v2/agateservice"(controller:"vertest", action:"agateSer", namespace:"v2")
v1 VertestController解析为v2 VertestService:
http://localhost:8080/worklists/v1/agateservice > com.iii.worklists.v2.VertestService
http://localhost:8080/worklists/v2/agateservice > com.iii.worklists.v2.VertestService
也许有一种方法可以强制v1 VertestController使用v1 VertestService;修改v1 VertestController以声明一个完全限定的VertestService:
package com.vertest.v1
class VertestController {
static namespace = 'v1'
com.vertest.v1.VertestService vertestService = new com.vertest.v1.VertestService()
def agateSer() {
render vertestService.agate()
}
}
哎哟!编译错误:
Error creating bean with name 'com.iii.worklists.v1.VertestController': Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'com.iii.worklists.v2.VertestService' to required type 'com.iii.worklists.v1.VertestService' for property 'vertestService'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [com.iii.worklists.v2.VertestService] to required type [com.iii.worklists.v1.VertestService] for property 'vertestService': no matching editors or conversion strategy found
将v1控制器与v1服务关联的首选方法是什么?
答案 0 :(得分:1)
应用程序不支持定义具有相同名称的2个服务,即使它们位于不同的包中。这样做的问题是它们都具有相同的bean名称。当不同插件提供具有相同名称的服务时,框架中存在处理此问题的机制,但这与在应用程序中定义它们不同,框架只是不支持。