Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Meiracle
spring-framework
提交
c48da0d9
S
spring-framework
项目概览
Meiracle
/
spring-framework
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
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,发现更多精彩内容 >>
提交
c48da0d9
编写于
1月 03, 2014
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Avoid hard reference to LocalValidatorFactoryBean in <mvc:annotation-driven> parser
Issue: SPR-11272
上级
e3344898
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
28 addition
and
26 deletion
+28
-26
spring-context/src/main/java/org/springframework/validation/beanvalidation/LocalValidatorFactoryBean.java
.../validation/beanvalidation/LocalValidatorFactoryBean.java
+4
-1
spring-webmvc/src/main/java/org/springframework/web/servlet/config/AnnotationDrivenBeanDefinitionParser.java
.../servlet/config/AnnotationDrivenBeanDefinitionParser.java
+24
-25
未找到文件。
spring-context/src/main/java/org/springframework/validation/beanvalidation/LocalValidatorFactoryBean.java
浏览文件 @
c48da0d9
...
...
@@ -57,6 +57,9 @@ import org.springframework.util.CollectionUtils;
* {@link #setValidationMessageSource} won't work in that scenario. Please stick with
* Hibernate Validator 4.3 for the time being, or upgrade to Spring Framework 4.0.
*
* <p>This class is also being used by Spring's MVC configuration namespace, in case of the
* {@code javax.validation} API being present but no explicit Validator having been configured.
*
* @author Juergen Hoeller
* @since 3.0
* @see javax.validation.ValidatorFactory
...
...
@@ -143,7 +146,7 @@ public class LocalValidatorFactoryBean extends SpringValidatorAdapter
/**
* Specify resource locations to load XML constraint mapping files from, if any.
*/
public
void
setMappingLocations
(
Resource
[]
mappingLocations
)
{
public
void
setMappingLocations
(
Resource
...
mappingLocations
)
{
this
.
mappingLocations
=
mappingLocations
;
}
...
...
spring-webmvc/src/main/java/org/springframework/web/servlet/config/AnnotationDrivenBeanDefinitionParser.java
浏览文件 @
c48da0d9
/*
* Copyright 2002-201
2
the original author or authors.
* Copyright 2002-201
3
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -19,6 +19,8 @@ package org.springframework.web.servlet.config;
import
java.util.List
;
import
java.util.Properties
;
import
org.w3c.dom.Element
;
import
org.springframework.beans.factory.config.BeanDefinition
;
import
org.springframework.beans.factory.config.BeanDefinitionHolder
;
import
org.springframework.beans.factory.config.RuntimeBeanReference
;
...
...
@@ -67,7 +69,6 @@ import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandl
import
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping
;
import
org.springframework.web.servlet.mvc.method.annotation.ServletWebArgumentResolverAdapter
;
import
org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver
;
import
org.w3c.dom.Element
;
/**
* A {@link BeanDefinitionParser} that provides the configuration for the
...
...
@@ -125,7 +126,7 @@ import org.w3c.dom.Element;
*/
class
AnnotationDrivenBeanDefinitionParser
implements
BeanDefinitionParser
{
private
static
final
boolean
j
sr303
Present
=
ClassUtils
.
isPresent
(
private
static
final
boolean
j
avaxValidation
Present
=
ClassUtils
.
isPresent
(
"javax.validation.Validator"
,
AnnotationDrivenBeanDefinitionParser
.
class
.
getClassLoader
());
private
static
final
boolean
jaxb2Present
=
...
...
@@ -142,6 +143,7 @@ class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser {
private
static
boolean
romePresent
=
ClassUtils
.
isPresent
(
"com.sun.syndication.feed.WireFeed"
,
AnnotationDrivenBeanDefinitionParser
.
class
.
getClassLoader
());
public
BeanDefinition
parse
(
Element
element
,
ParserContext
parserContext
)
{
Object
source
=
parserContext
.
extractSource
(
element
);
...
...
@@ -274,8 +276,9 @@ class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser {
if
(
element
.
hasAttribute
(
"validator"
))
{
return
new
RuntimeBeanReference
(
element
.
getAttribute
(
"validator"
));
}
else
if
(
jsr303Present
)
{
RootBeanDefinition
validatorDef
=
new
RootBeanDefinition
(
LocalValidatorFactoryBean
.
class
);
else
if
(
javaxValidationPresent
)
{
RootBeanDefinition
validatorDef
=
new
RootBeanDefinition
(
"org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"
);
validatorDef
.
setSource
(
source
);
validatorDef
.
setRole
(
BeanDefinition
.
ROLE_INFRASTRUCTURE
);
String
validatorName
=
parserContext
.
getReaderContext
().
registerWithGeneratedName
(
validatorDef
);
...
...
@@ -324,7 +327,8 @@ class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser {
private
RuntimeBeanReference
getMessageCodesResolver
(
Element
element
,
Object
source
,
ParserContext
parserContext
)
{
if
(
element
.
hasAttribute
(
"message-codes-resolver"
))
{
return
new
RuntimeBeanReference
(
element
.
getAttribute
(
"message-codes-resolver"
));
}
else
{
}
else
{
return
null
;
}
}
...
...
@@ -400,7 +404,7 @@ class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser {
ManagedList
<?
super
Object
>
messageConverters
=
new
ManagedList
<
Object
>();
if
(
convertersElement
!=
null
)
{
messageConverters
.
setSource
(
source
);
for
(
Element
beanElement
:
DomUtils
.
getChildElementsByTagName
(
convertersElement
,
new
String
[]
{
"bean"
,
"ref"
}
))
{
for
(
Element
beanElement
:
DomUtils
.
getChildElementsByTagName
(
convertersElement
,
"bean"
,
"ref"
))
{
Object
object
=
parserContext
.
getDelegate
().
parsePropertySubElement
(
beanElement
,
null
);
messageConverters
.
add
(
object
);
}
...
...
@@ -408,40 +412,37 @@ class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser {
if
(
convertersElement
==
null
||
Boolean
.
valueOf
(
convertersElement
.
getAttribute
(
"register-defaults"
)))
{
messageConverters
.
setSource
(
source
);
messageConverters
.
add
(
createConverter
Bean
Definition
(
ByteArrayHttpMessageConverter
.
class
,
source
));
messageConverters
.
add
(
createConverterDefinition
(
ByteArrayHttpMessageConverter
.
class
,
source
));
RootBeanDefinition
stringConverterDef
=
createConverter
Bean
Definition
(
StringHttpMessageConverter
.
class
,
source
);
RootBeanDefinition
stringConverterDef
=
createConverterDefinition
(
StringHttpMessageConverter
.
class
,
source
);
stringConverterDef
.
getPropertyValues
().
add
(
"writeAcceptCharset"
,
false
);
messageConverters
.
add
(
stringConverterDef
);
messageConverters
.
add
(
createConverter
Bean
Definition
(
ResourceHttpMessageConverter
.
class
,
source
));
messageConverters
.
add
(
createConverter
Bean
Definition
(
SourceHttpMessageConverter
.
class
,
source
));
messageConverters
.
add
(
createConverter
Bean
Definition
(
AllEncompassingFormHttpMessageConverter
.
class
,
source
));
messageConverters
.
add
(
createConverterDefinition
(
ResourceHttpMessageConverter
.
class
,
source
));
messageConverters
.
add
(
createConverterDefinition
(
SourceHttpMessageConverter
.
class
,
source
));
messageConverters
.
add
(
createConverterDefinition
(
AllEncompassingFormHttpMessageConverter
.
class
,
source
));
if
(
romePresent
)
{
messageConverters
.
add
(
createConverter
Bean
Definition
(
AtomFeedHttpMessageConverter
.
class
,
source
));
messageConverters
.
add
(
createConverter
Bean
Definition
(
RssChannelHttpMessageConverter
.
class
,
source
));
messageConverters
.
add
(
createConverterDefinition
(
AtomFeedHttpMessageConverter
.
class
,
source
));
messageConverters
.
add
(
createConverterDefinition
(
RssChannelHttpMessageConverter
.
class
,
source
));
}
if
(
jaxb2Present
)
{
messageConverters
.
add
(
createConverter
Bean
Definition
(
Jaxb2RootElementHttpMessageConverter
.
class
,
source
));
.
add
(
createConverterDefinition
(
Jaxb2RootElementHttpMessageConverter
.
class
,
source
));
}
if
(
jackson2Present
)
{
messageConverters
.
add
(
createConverter
Bean
Definition
(
MappingJackson2HttpMessageConverter
.
class
,
source
));
messageConverters
.
add
(
createConverterDefinition
(
MappingJackson2HttpMessageConverter
.
class
,
source
));
}
else
if
(
jacksonPresent
)
{
messageConverters
.
add
(
createConverter
Bean
Definition
(
MappingJacksonHttpMessageConverter
.
class
,
source
));
messageConverters
.
add
(
createConverterDefinition
(
MappingJacksonHttpMessageConverter
.
class
,
source
));
}
}
return
messageConverters
;
}
private
RootBeanDefinition
createConverterBeanDefinition
(
Class
<?
extends
HttpMessageConverter
>
converterClass
,
Object
source
)
{
private
RootBeanDefinition
createConverterDefinition
(
Class
<?
extends
HttpMessageConverter
>
converterClass
,
Object
source
)
{
RootBeanDefinition
beanDefinition
=
new
RootBeanDefinition
(
converterClass
);
beanDefinition
.
setSource
(
source
);
beanDefinition
.
setRole
(
BeanDefinition
.
ROLE_INFRASTRUCTURE
);
return
beanDefinition
;
}
...
...
@@ -458,20 +459,18 @@ class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser {
private
ManagedList
<
BeanDefinitionHolder
>
wrapWebArgumentResolverBeanDefs
(
List
<
BeanDefinitionHolder
>
beanDefs
)
{
ManagedList
<
BeanDefinitionHolder
>
result
=
new
ManagedList
<
BeanDefinitionHolder
>();
for
(
BeanDefinitionHolder
beanDef
:
beanDefs
)
{
String
className
=
beanDef
.
getBeanDefinition
().
getBeanClassName
();
Class
<?>
clazz
=
ClassUtils
.
resolveClassName
(
className
,
ClassUtils
.
getDefaultClassLoader
());
if
(
WebArgumentResolver
.
class
.
isAssignableFrom
(
clazz
))
{
RootBeanDefinition
adapter
=
new
RootBeanDefinition
(
ServletWebArgumentResolverAdapter
.
class
);
adapter
.
getConstructorArgumentValues
().
addIndexedArgumentValue
(
0
,
beanDef
);
result
.
add
(
new
BeanDefinitionHolder
(
adapter
,
beanDef
.
getBeanName
()
+
"Adapter"
));
}
else
{
}
else
{
result
.
add
(
beanDef
);
}
}
return
result
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录