Grails 4升级后,我的URL映射和拦截器不再工作
我试图将3.3.x升级到4.0.13,但是这样做之后,我的URL映射和拦截器不再工作。我相信,由于我在拦截器中的调试陈述,这两个问题之间存在一个相同的问题,这使得它在基础的圣杯映射中似乎被打破了。
URLMappings
static mappings = {
"/api/admin/$controller/$action?/$id?(.$format)?"{
namespace = "admin"
constraints {
// apply constraints here
}
}
"/"(redirect: "/app/")
"/app"(uri: "/index.html")
"/app/**"(uri: "/index.html")
"500"(view:'/error')
"404"(redirect: "/app/")
}
UserController
class UserController extends AdminController {
static namespace = "admin";
def save(UserCommand cmd) {
[...]
}
}
LoginInterceptor
class LoginInterceptor {
LoginInterceptor() {
matchAll()
.excludes(controller: ~/(login|logout|publicLookupSvc)/);
}
boolean before() {
println(controllerNamespace);
println(controllerName);
println(actionName);
println(request.requestURI);
true
}
}
So the underlying issue I am referring to is that my debug statments in 4.0.13 print null
whereas in 3.3.x they actually print values
So if I visit the URL: http://localhost :8081/raa/api/admin/user/save
In 3.3
println(controllerNamespace); -> admin
println(controllerName); -> user
println(actionName); -> save
println(request.requestURI); -> /raa/api/admin/user/save
In 4.0.13
println(controllerNamespace); -> null
println(controllerName); -> null
println(actionName); -> null
println(request.requestURI); -> /raa/api/admin/user/save
Along with the error stacktrace
2022-04-20 13:15:33.303 ERROR --- [nio-8081-exec-3] o.g.web.errors.GrailsExceptionResolver : IllegalArgumentException occurred when processing request: [GET] /raa/api/admin/user/save
URL mapping must either provide redirect information, a controller or a view name to map to!. Stacktrace follows:
java.lang.IllegalArgumentException: URL mapping must either provide redirect information, a controller or a view name to map to!
at org.springframework.util.Assert.isTrue(Assert.java:118)
at org.grails.web.mapping.DefaultUrlMappingInfo.<init>(DefaultUrlMappingInfo.java:105)
at org.grails.web.mapping.DefaultUrlMappingInfo.<init>(DefaultUrlMappingInfo.java:99)
at org.grails.web.mapping.ResponseCodeUrlMapping.match(ResponseCodeUrlMapping.java:136)
[...]
Consequently, since all the attributes are null regarding where my request is suposed to be routed, the matchAll()也不起作用。当我在
登录/注销/publiclookupsvc
控制器中,即使应该跳过,拦截器仍会被击中。
我觉得一旦我弄清楚为什么这些映射参数无法正确填充,一切都会落在原位。我只是不知道为什么会发生。
Grails 4.0.13
JDK 11.0.13
Gradle 5.0
I am trying to upgrade from 3.3.x to 4.0.13 but after doing so my URL mappings and interceptors no longer work. I believe there is a root issue that is the same between the 2 because of debug statements I have in my interceptor make it appear someone in the underlying grails mappings is broken.
URLMappings
static mappings = {
"/api/admin/$controller/$action?/$id?(.$format)?"{
namespace = "admin"
constraints {
// apply constraints here
}
}
"/"(redirect: "/app/")
"/app"(uri: "/index.html")
"/app/**"(uri: "/index.html")
"500"(view:'/error')
"404"(redirect: "/app/")
}
UserController
class UserController extends AdminController {
static namespace = "admin";
def save(UserCommand cmd) {
[...]
}
}
LoginInterceptor
class LoginInterceptor {
LoginInterceptor() {
matchAll()
.excludes(controller: ~/(login|logout|publicLookupSvc)/);
}
boolean before() {
println(controllerNamespace);
println(controllerName);
println(actionName);
println(request.requestURI);
true
}
}
So the underlying issue I am referring to is that my debug statments in 4.0.13 print null
whereas in 3.3.x they actually print values
So if I visit the URL: http://localhost:8081/raa/api/admin/user/save
In 3.3
println(controllerNamespace); -> admin
println(controllerName); -> user
println(actionName); -> save
println(request.requestURI); -> /raa/api/admin/user/save
In 4.0.13
println(controllerNamespace); -> null
println(controllerName); -> null
println(actionName); -> null
println(request.requestURI); -> /raa/api/admin/user/save
Along with the error stacktrace
2022-04-20 13:15:33.303 ERROR --- [nio-8081-exec-3] o.g.web.errors.GrailsExceptionResolver : IllegalArgumentException occurred when processing request: [GET] /raa/api/admin/user/save
URL mapping must either provide redirect information, a controller or a view name to map to!. Stacktrace follows:
java.lang.IllegalArgumentException: URL mapping must either provide redirect information, a controller or a view name to map to!
at org.springframework.util.Assert.isTrue(Assert.java:118)
at org.grails.web.mapping.DefaultUrlMappingInfo.<init>(DefaultUrlMappingInfo.java:105)
at org.grails.web.mapping.DefaultUrlMappingInfo.<init>(DefaultUrlMappingInfo.java:99)
at org.grails.web.mapping.ResponseCodeUrlMapping.match(ResponseCodeUrlMapping.java:136)
[...]
Consequently, since all the attributes are null regarding where my request is suposed to be routed, the matchAll()
does not work either. When I vist my login/logout/publicLookupSvc
controllers the interceptor still gets hit even though it should be skipped.
I feel like once I figure out why those mapping paramters are not being populated correctly everything will fall into place. I just can't figure out why thats happening.
Grails 4.0.13
JDK 11.0.13
Gradle 5.0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在Grails 4.x中宣传
上下文Path的方式已更改,这导致我所有的URL不正确。修复此操作后,一切都按预期运行。
Grails 3.x
Grails 4.x+
The way you delcared your
contextPath
in Grails 4.x has changed and this was causing all my URL to be incorrect. After fixing this everything worked as expected.Grails 3.x
Grails 4.x+