Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
普通程序员一名
spring-framework
提交
44b76d39
S
spring-framework
项目概览
普通程序员一名
/
spring-framework
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
44b76d39
编写于
10月 07, 2015
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ExceptionHandlerExceptionResolver allows for Model parameter
Issue: SPR-13546
上级
966f95b9
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
45 addition
and
3 deletion
+45
-3
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolver.java
.../method/annotation/ExceptionHandlerExceptionResolver.java
+1
-0
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolverTests.java
...od/annotation/ExceptionHandlerExceptionResolverTests.java
+44
-3
未找到文件。
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolver.java
浏览文件 @
44b76d39
...
...
@@ -293,6 +293,7 @@ public class ExceptionHandlerExceptionResolver extends AbstractHandlerMethodExce
// Type-based argument resolution
resolvers
.
add
(
new
ServletRequestMethodArgumentResolver
());
resolvers
.
add
(
new
ServletResponseMethodArgumentResolver
());
resolvers
.
add
(
new
ModelMethodProcessor
());
// Custom arguments
if
(
getCustomArgumentResolvers
()
!=
null
)
{
...
...
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolverTests.java
浏览文件 @
44b76d39
...
...
@@ -32,6 +32,7 @@ import org.springframework.core.annotation.Order;
import
org.springframework.mock.web.test.MockHttpServletRequest
;
import
org.springframework.mock.web.test.MockHttpServletResponse
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.util.ClassUtils
;
import
org.springframework.web.bind.annotation.ControllerAdvice
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
...
...
@@ -49,6 +50,7 @@ import static org.junit.Assert.*;
*
* @author Rossen Stoyanchev
* @author Arjen Poutsma
* @author Kazuki Shimizu
* @since 3.1
*/
public
class
ExceptionHandlerExceptionResolverTests
{
...
...
@@ -63,6 +65,7 @@ public class ExceptionHandlerExceptionResolverTests {
private
MockHttpServletResponse
response
;
@BeforeClass
public
static
void
setupOnce
()
{
ExceptionHandlerExceptionResolver
r
=
new
ExceptionHandlerExceptionResolver
();
...
...
@@ -72,12 +75,13 @@ public class ExceptionHandlerExceptionResolverTests {
}
@Before
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
this
.
resolver
=
new
ExceptionHandlerExceptionResolver
();
this
.
request
=
new
MockHttpServletRequest
(
"GET"
,
"/"
);
this
.
response
=
new
MockHttpServletResponse
();
}
@Test
public
void
nullHandler
()
{
Object
handler
=
null
;
...
...
@@ -171,6 +175,18 @@ public class ExceptionHandlerExceptionResolverTests {
assertEquals
(
"IllegalArgumentException"
,
this
.
response
.
getContentAsString
());
}
@Test
// SPR-13546
public
void
resolveExceptionModelAtArgument
()
throws
Exception
{
IllegalArgumentException
ex
=
new
IllegalArgumentException
();
HandlerMethod
handlerMethod
=
new
HandlerMethod
(
new
ModelArgumentController
(),
"handle"
);
this
.
resolver
.
afterPropertiesSet
();
ModelAndView
mav
=
this
.
resolver
.
resolveException
(
this
.
request
,
this
.
response
,
handlerMethod
,
ex
);
assertNotNull
(
mav
);
assertEquals
(
1
,
mav
.
getModelMap
().
size
());
assertEquals
(
"IllegalArgumentException"
,
mav
.
getModelMap
().
get
(
"exceptionClassName"
));
}
@Test
public
void
resolveExceptionGlobalHandler
()
throws
Exception
{
AnnotationConfigApplicationContext
cxt
=
new
AnnotationConfigApplicationContext
(
MyConfig
.
class
);
...
...
@@ -253,6 +269,7 @@ public class ExceptionHandlerExceptionResolverTests {
assertEquals
(
handlerCount
,
this
.
resolver
.
getReturnValueHandlers
().
getHandlers
().
size
());
}
@Controller
static
class
ModelAndViewController
{
...
...
@@ -264,6 +281,7 @@ public class ExceptionHandlerExceptionResolverTests {
}
}
@Controller
static
class
ResponseWriterController
{
...
...
@@ -275,6 +293,7 @@ public class ExceptionHandlerExceptionResolverTests {
}
}
@Controller
static
class
ResponseBodyController
{
...
...
@@ -287,16 +306,30 @@ public class ExceptionHandlerExceptionResolverTests {
}
}
@Controller
static
class
IoExceptionController
{
public
void
handle
()
{}
@ExceptionHandler
(
value
=
IOException
.
class
)
@ExceptionHandler
(
value
=
IOException
.
class
)
public
void
handleException
()
{
}
}
@Controller
static
class
ModelArgumentController
{
public
void
handle
()
{}
@ExceptionHandler
public
void
handleException
(
Exception
ex
,
Model
model
)
{
model
.
addAttribute
(
"exceptionClassName"
,
ClassUtils
.
getShortName
(
ex
.
getClass
()));
}
}
@ControllerAdvice
@Order
(
1
)
static
class
TestExceptionResolver
{
...
...
@@ -314,6 +347,7 @@ public class ExceptionHandlerExceptionResolverTests {
}
}
@ControllerAdvice
@Order
(
2
)
static
class
AnotherTestExceptionResolver
{
...
...
@@ -325,6 +359,7 @@ public class ExceptionHandlerExceptionResolverTests {
}
}
@Configuration
static
class
MyConfig
{
...
...
@@ -337,6 +372,7 @@ public class ExceptionHandlerExceptionResolverTests {
}
}
@ControllerAdvice
(
"java.lang"
)
@Order
(
1
)
static
class
NotCalledTestExceptionResolver
{
...
...
@@ -348,6 +384,7 @@ public class ExceptionHandlerExceptionResolverTests {
}
}
@ControllerAdvice
(
"org.springframework.web.servlet.mvc.method.annotation"
)
@Order
(
2
)
static
class
BasePackageTestExceptionResolver
{
...
...
@@ -359,6 +396,7 @@ public class ExceptionHandlerExceptionResolverTests {
}
}
@ControllerAdvice
@Order
(
3
)
static
class
DefaultTestExceptionResolver
{
...
...
@@ -370,8 +408,10 @@ public class ExceptionHandlerExceptionResolverTests {
}
}
@Configuration
static
class
MyControllerAdviceConfig
{
@Bean
public
NotCalledTestExceptionResolver
notCalledTestExceptionResolver
()
{
return
new
NotCalledTestExceptionResolver
();
}
...
...
@@ -384,4 +424,5 @@ public class ExceptionHandlerExceptionResolverTests {
return
new
DefaultTestExceptionResolver
();
}
}
}
\ No newline at end of file
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录