Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
1f4ca61b
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
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,体验更适合开发者的 AI 搜索 >>
提交
1f4ca61b
编写于
5月 03, 2019
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polishing
上级
2e7489d1
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
92 addition
and
67 deletion
+92
-67
spring-beans/src/main/java/org/springframework/beans/factory/config/InstantiationAwareBeanPostProcessor.java
...s/factory/config/InstantiationAwareBeanPostProcessor.java
+10
-8
spring-core/src/main/java/org/springframework/core/type/filter/AbstractTypeHierarchyTraversingFilter.java
...re/type/filter/AbstractTypeHierarchyTraversingFilter.java
+10
-6
spring-jdbc/src/main/java/org/springframework/jdbc/support/CustomSQLExceptionTranslatorRegistry.java
...rk/jdbc/support/CustomSQLExceptionTranslatorRegistry.java
+11
-9
spring-jms/src/main/java/org/springframework/jms/listener/endpoint/DefaultJmsActivationSpecFactory.java
...ms/listener/endpoint/DefaultJmsActivationSpecFactory.java
+13
-5
spring-tx/src/main/java/org/springframework/transaction/PlatformTransactionManager.java
...ringframework/transaction/PlatformTransactionManager.java
+2
-3
spring-tx/src/main/java/org/springframework/transaction/annotation/Propagation.java
...g/springframework/transaction/annotation/Propagation.java
+3
-3
spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAspectSupport.java
...ork/transaction/interceptor/TransactionAspectSupport.java
+10
-7
spring-tx/src/main/java/org/springframework/transaction/support/AbstractPlatformTransactionManager.java
...ansaction/support/AbstractPlatformTransactionManager.java
+6
-5
spring-tx/src/main/java/org/springframework/transaction/support/TransactionSynchronizationManager.java
...ransaction/support/TransactionSynchronizationManager.java
+4
-3
spring-web/src/main/java/org/springframework/web/method/annotation/AbstractWebArgumentResolverAdapter.java
...method/annotation/AbstractWebArgumentResolverAdapter.java
+4
-2
spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerExceptionResolver.java
...web/servlet/handler/AbstractHandlerExceptionResolver.java
+3
-4
spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/CookieLocaleResolver.java
...pringframework/web/servlet/i18n/CookieLocaleResolver.java
+12
-10
spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/LocaleChangeInterceptor.java
...ngframework/web/servlet/i18n/LocaleChangeInterceptor.java
+4
-2
未找到文件。
spring-beans/src/main/java/org/springframework/beans/factory/config/InstantiationAwareBeanPostProcessor.java
浏览文件 @
1f4ca61b
/*
* Copyright 2002-201
7
the original author or authors.
* Copyright 2002-201
9
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.
...
...
@@ -53,8 +53,9 @@ public interface InstantiationAwareBeanPostProcessor extends BeanPostProcessor {
* will be short-circuited. The only further processing applied is the
* {@link #postProcessAfterInitialization} callback from the configured
* {@link BeanPostProcessor BeanPostProcessors}.
* <p>This callback will only be applied to bean definitions with a bean class.
* In particular, it will not be applied to beans with a "factory-method".
* <p>This callback will be applied to bean definitions with their bean class,
* as well as to factory-method definitions in which case the returned bean type
* will be passed in here.
* <p>Post-processors may implement the extended
* {@link SmartInstantiationAwareBeanPostProcessor} interface in order
* to predict the type of the bean object that they are going to return here.
...
...
@@ -63,8 +64,9 @@ public interface InstantiationAwareBeanPostProcessor extends BeanPostProcessor {
* @return the bean object to expose instead of a default instance of the target bean,
* or {@code null} to proceed with default instantiation
* @throws org.springframework.beans.BeansException in case of errors
* @see org.springframework.beans.factory.support.AbstractBeanDefinition#hasBeanClass
* @see org.springframework.beans.factory.support.AbstractBeanDefinition#getFactoryMethodName
* @see #postProcessAfterInstantiation
* @see org.springframework.beans.factory.support.AbstractBeanDefinition#getBeanClass()
* @see org.springframework.beans.factory.support.AbstractBeanDefinition#getFactoryMethodName()
*/
Object
postProcessBeforeInstantiation
(
Class
<?>
beanClass
,
String
beanName
)
throws
BeansException
;
...
...
@@ -80,6 +82,7 @@ public interface InstantiationAwareBeanPostProcessor extends BeanPostProcessor {
* Returning {@code false} will also prevent any subsequent InstantiationAwareBeanPostProcessor
* instances being invoked on this bean instance.
* @throws org.springframework.beans.BeansException in case of errors
* @see #postProcessBeforeInstantiation
*/
boolean
postProcessAfterInstantiation
(
Object
bean
,
String
beanName
)
throws
BeansException
;
...
...
@@ -95,9 +98,8 @@ public interface InstantiationAwareBeanPostProcessor extends BeanPostProcessor {
* dependency types - which the factory handles specifically - already filtered out)
* @param bean the bean instance created, but whose properties have not yet been set
* @param beanName the name of the bean
* @return the actual property values to apply to the given bean
* (can be the passed-in PropertyValues instance), or {@code null}
* to skip property population
* @return the actual property values to apply to the given bean (can be the passed-in
* PropertyValues instance), or {@code null} to skip property population
* @throws org.springframework.beans.BeansException in case of errors
* @see org.springframework.beans.MutablePropertyValues
*/
...
...
spring-core/src/main/java/org/springframework/core/type/filter/AbstractTypeHierarchyTraversingFilter.java
浏览文件 @
1f4ca61b
/*
* Copyright 2002-201
4
the original author or authors.
* Copyright 2002-201
9
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.
...
...
@@ -83,10 +83,12 @@ public abstract class AbstractTypeHierarchyTraversingFilter implements TypeFilte
}
}
catch
(
IOException
ex
)
{
logger
.
debug
(
"Could not read super class ["
+
metadata
.
getSuperClassName
()
+
"] of type-filtered class ["
+
metadata
.
getClassName
()
+
"]"
);
if
(
logger
.
isDebugEnabled
())
{
logger
.
debug
(
"Could not read super class ["
+
metadata
.
getSuperClassName
()
+
"] of type-filtered class ["
+
metadata
.
getClassName
()
+
"]"
);
}
}
}
}
}
}
...
...
@@ -107,8 +109,10 @@ public abstract class AbstractTypeHierarchyTraversingFilter implements TypeFilte
}
}
catch
(
IOException
ex
)
{
logger
.
debug
(
"Could not read interface ["
+
ifc
+
"] for type-filtered class ["
+
metadata
.
getClassName
()
+
"]"
);
if
(
logger
.
isDebugEnabled
())
{
logger
.
debug
(
"Could not read interface ["
+
ifc
+
"] for type-filtered class ["
+
metadata
.
getClassName
()
+
"]"
);
}
}
}
}
...
...
spring-jdbc/src/main/java/org/springframework/jdbc/support/CustomSQLExceptionTranslatorRegistry.java
浏览文件 @
1f4ca61b
/*
* Copyright 2002-201
2
the original author or authors.
* Copyright 2002-201
9
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.
...
...
@@ -70,14 +70,16 @@ public class CustomSQLExceptionTranslatorRegistry {
* @param translator the custom translator
*/
public
void
registerTranslator
(
String
dbName
,
SQLExceptionTranslator
translator
)
{
SQLExceptionTranslator
replaced
=
translatorMap
.
put
(
dbName
,
translator
);
if
(
replaced
!=
null
)
{
logger
.
warn
(
"Replacing custom translator ["
+
replaced
+
"] for database '"
+
dbName
+
"' with ["
+
translator
+
"]"
);
}
else
{
logger
.
info
(
"Adding custom translator of type ["
+
translator
.
getClass
().
getName
()
+
"] for database '"
+
dbName
+
"'"
);
SQLExceptionTranslator
replaced
=
this
.
translatorMap
.
put
(
dbName
,
translator
);
if
(
logger
.
isInfoEnabled
())
{
if
(
replaced
!=
null
)
{
logger
.
info
(
"Replacing custom translator ["
+
replaced
+
"] for database '"
+
dbName
+
"' with ["
+
translator
+
"]"
);
}
else
{
logger
.
info
(
"Adding custom translator of type ["
+
translator
.
getClass
().
getName
()
+
"] for database '"
+
dbName
+
"'"
);
}
}
}
...
...
spring-jms/src/main/java/org/springframework/jms/listener/endpoint/DefaultJmsActivationSpecFactory.java
浏览文件 @
1f4ca61b
/*
* Copyright 2002-201
4
the original author or authors.
* Copyright 2002-201
9
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.
...
...
@@ -85,7 +85,9 @@ public class DefaultJmsActivationSpecFactory extends StandardJmsActivationSpecFa
return
adapter
.
getClass
().
getClassLoader
().
loadClass
(
specClassName
);
}
catch
(
ClassNotFoundException
ex
)
{
logger
.
debug
(
"No default <Provider>ActivationSpec class found: "
+
specClassName
);
if
(
logger
.
isDebugEnabled
())
{
logger
.
debug
(
"No default <Provider>ActivationSpec class found: "
+
specClassName
);
}
}
}
...
...
@@ -98,7 +100,9 @@ public class DefaultJmsActivationSpecFactory extends StandardJmsActivationSpecFa
return
adapter
.
getClass
().
getClassLoader
().
loadClass
(
specClassName
);
}
catch
(
ClassNotFoundException
ex
)
{
logger
.
debug
(
"No default <Provider>ActivationSpecImpl class found: "
+
specClassName
);
if
(
logger
.
isDebugEnabled
())
{
logger
.
debug
(
"No default <Provider>ActivationSpecImpl class found: "
+
specClassName
);
}
}
}
...
...
@@ -109,7 +113,9 @@ public class DefaultJmsActivationSpecFactory extends StandardJmsActivationSpecFa
return
adapter
.
getClass
().
getClassLoader
().
loadClass
(
specClassName
);
}
catch
(
ClassNotFoundException
ex
)
{
logger
.
debug
(
"No default ActivationSpecImpl class found in provider package: "
+
specClassName
);
if
(
logger
.
isDebugEnabled
())
{
logger
.
debug
(
"No default ActivationSpecImpl class found in provider package: "
+
specClassName
);
}
}
// ActivationSpecImpl class in "inbound" subpackage (WebSphere MQ 6.0.2.1)
...
...
@@ -118,7 +124,9 @@ public class DefaultJmsActivationSpecFactory extends StandardJmsActivationSpecFa
return
adapter
.
getClass
().
getClassLoader
().
loadClass
(
specClassName
);
}
catch
(
ClassNotFoundException
ex
)
{
logger
.
debug
(
"No default ActivationSpecImpl class found in inbound subpackage: "
+
specClassName
);
if
(
logger
.
isDebugEnabled
())
{
logger
.
debug
(
"No default ActivationSpecImpl class found in inbound subpackage: "
+
specClassName
);
}
}
throw
new
IllegalStateException
(
"No ActivationSpec class defined - "
+
...
...
spring-tx/src/main/java/org/springframework/transaction/PlatformTransactionManager.java
浏览文件 @
1f4ca61b
/*
* Copyright 2002-201
2
the original author or authors.
* Copyright 2002-201
9
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.
...
...
@@ -39,7 +39,6 @@ package org.springframework.transaction;
* @since 16.05.2003
* @see org.springframework.transaction.support.TransactionTemplate
* @see org.springframework.transaction.interceptor.TransactionInterceptor
* @see org.springframework.transaction.interceptor.TransactionProxyFactoryBean
*/
public
interface
PlatformTransactionManager
{
...
...
@@ -54,7 +53,7 @@ public interface PlatformTransactionManager {
* <p>An exception to the above rule is the read-only flag, which should be
* ignored if no explicit read-only mode is supported. Essentially, the
* read-only flag is just a hint for potential optimization.
* @param definition TransactionDefinition instance (can be {@code null} for defaults),
* @param definition
the
TransactionDefinition instance (can be {@code null} for defaults),
* describing propagation behavior, isolation level, timeout etc.
* @return transaction status object representing the new or current transaction
* @throws TransactionException in case of lookup, creation, or system errors
...
...
spring-tx/src/main/java/org/springframework/transaction/annotation/Propagation.java
浏览文件 @
1f4ca61b
...
...
@@ -87,11 +87,11 @@ public enum Propagation {
/**
* Execute within a nested transaction if a current transaction exists,
* behave like {@code REQUIRED}
el
se. There is no analogous feature in EJB.
* behave like {@code REQUIRED}
otherwi
se. There is no analogous feature in EJB.
* <p>Note: Actual creation of a nested transaction will only work on specific
* transaction managers. Out of the box, this only applies to the JDBC
* DataSourceTransactionManager
when working on a JDBC 3.0 driver.
*
Some JTA providers might support nested
transactions as well.
* DataSourceTransactionManager
. Some JTA providers might support nested
* transactions as well.
* @see org.springframework.jdbc.datasource.DataSourceTransactionManager
*/
NESTED
(
TransactionDefinition
.
PROPAGATION_NESTED
);
...
...
spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAspectSupport.java
浏览文件 @
1f4ca61b
/*
* Copyright 2002-201
7
the original author or authors.
* Copyright 2002-201
9
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.
...
...
@@ -100,7 +100,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
* <p>To find out about specific transaction characteristics, consider using
* TransactionSynchronizationManager's {@code isSynchronizationActive()}
* and/or {@code isActualTransactionActive()} methods.
* @return TransactionInfo bound to this thread, or {@code null} if none
* @return
the
TransactionInfo bound to this thread, or {@code null} if none
* @see TransactionInfo#hasTransaction()
* @see org.springframework.transaction.support.TransactionSynchronizationManager#isSynchronizationActive()
* @see org.springframework.transaction.support.TransactionSynchronizationManager#isActualTransactionActive()
...
...
@@ -275,7 +275,8 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
if
(
txAttr
==
null
||
!(
tm
instanceof
CallbackPreferringPlatformTransactionManager
))
{
// Standard transaction demarcation with getTransaction and commit/rollback calls.
TransactionInfo
txInfo
=
createTransactionIfNecessary
(
tm
,
txAttr
,
joinpointIdentification
);
Object
retVal
=
null
;
Object
retVal
;
try
{
// This is an around advice: Invoke the next interceptor in the chain.
// This will normally result in a target object being invoked.
...
...
@@ -369,6 +370,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
if
(
txAttr
==
null
||
this
.
beanFactory
==
null
)
{
return
getTransactionManager
();
}
String
qualifier
=
txAttr
.
getQualifier
();
if
(
StringUtils
.
hasText
(
qualifier
))
{
return
determineQualifiedTransactionManager
(
qualifier
);
...
...
@@ -493,9 +495,10 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
else
{
// The TransactionInfo.hasTransaction() method will return false. We created it only
// to preserve the integrity of the ThreadLocal stack maintained in this class.
if
(
logger
.
isTraceEnabled
())
logger
.
trace
(
"Don't need to create transaction for ["
+
joinpointIdentification
+
"]: This method isn't transactional."
);
if
(
logger
.
isTraceEnabled
())
{
logger
.
trace
(
"No need to create transaction for ["
+
joinpointIdentification
+
"]: This method is not transactional."
);
}
}
// We always bind the TransactionInfo to the thread, even if we didn't create
...
...
@@ -585,7 +588,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
/**
* Opaque object used to hold
T
ransaction information. Subclasses
* Opaque object used to hold
t
ransaction information. Subclasses
* must pass it back to methods on this class, but not see its internals.
*/
protected
final
class
TransactionInfo
{
...
...
spring-tx/src/main/java/org/springframework/transaction/support/AbstractPlatformTransactionManager.java
浏览文件 @
1f4ca61b
/*
* Copyright 2002-201
8
the original author or authors.
* Copyright 2002-201
9
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.
...
...
@@ -560,7 +560,7 @@ public abstract class AbstractPlatformTransactionManager implements PlatformTran
if
(
definition
.
getTimeout
()
!=
TransactionDefinition
.
TIMEOUT_DEFAULT
)
{
return
definition
.
getTimeout
();
}
return
this
.
defaultTimeout
;
return
getDefaultTimeout
()
;
}
...
...
@@ -682,7 +682,7 @@ public abstract class AbstractPlatformTransactionManager implements PlatformTran
/**
* Reactivate transaction synchronization for the current thread
* and resume all given synchronizations.
* @param suspendedSynchronizations List of TransactionSynchronization objects
* @param suspendedSynchronizations
a
List of TransactionSynchronization objects
*/
private
void
doResumeSynchronization
(
List
<
TransactionSynchronization
>
suspendedSynchronizations
)
{
TransactionSynchronizationManager
.
initSynchronization
();
...
...
@@ -994,7 +994,7 @@ public abstract class AbstractPlatformTransactionManager implements PlatformTran
* given Spring TransactionSynchronization objects.
* <p>To be called by this abstract manager itself, or by special implementations
* of the {@code registerAfterCompletionWithExistingTransaction} callback.
* @param synchronizations List of TransactionSynchronization objects
* @param synchronizations
a
List of TransactionSynchronization objects
* @param completionStatus the completion status according to the
* constants in the TransactionSynchronization interface
* @see #registerAfterCompletionWithExistingTransaction(Object, java.util.List)
...
...
@@ -1244,7 +1244,7 @@ public abstract class AbstractPlatformTransactionManager implements PlatformTran
* immediately, passing in "STATUS_UNKNOWN". This is the best we can do if there's no
* chance to determine the actual outcome of the outer transaction.
* @param transaction transaction object returned by {@code doGetTransaction}
* @param synchronizations List of TransactionSynchronization objects
* @param synchronizations
a
List of TransactionSynchronization objects
* @throws TransactionException in case of system errors
* @see #invokeAfterCompletion(java.util.List, int)
* @see TransactionSynchronization#afterCompletion(int)
...
...
@@ -1307,6 +1307,7 @@ public abstract class AbstractPlatformTransactionManager implements PlatformTran
private
SuspendedResourcesHolder
(
Object
suspendedResources
,
List
<
TransactionSynchronization
>
suspendedSynchronizations
,
String
name
,
boolean
readOnly
,
Integer
isolationLevel
,
boolean
wasActive
)
{
this
.
suspendedResources
=
suspendedResources
;
this
.
suspendedSynchronizations
=
suspendedSynchronizations
;
this
.
name
=
name
;
...
...
spring-tx/src/main/java/org/springframework/transaction/support/TransactionSynchronizationManager.java
浏览文件 @
1f4ca61b
/*
* Copyright 2002-201
7
the original author or authors.
* Copyright 2002-201
9
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.
...
...
@@ -287,10 +287,11 @@ public abstract class TransactionSynchronizationManager {
throws
IllegalStateException
{
Assert
.
notNull
(
synchronization
,
"TransactionSynchronization must not be null"
);
if
(!
isSynchronizationActive
())
{
Set
<
TransactionSynchronization
>
synchs
=
synchronizations
.
get
();
if
(
synchs
==
null
)
{
throw
new
IllegalStateException
(
"Transaction synchronization is not active"
);
}
synch
ronizations
.
get
()
.
add
(
synchronization
);
synch
s
.
add
(
synchronization
);
}
/**
...
...
spring-web/src/main/java/org/springframework/web/method/annotation/AbstractWebArgumentResolverAdapter.java
浏览文件 @
1f4ca61b
/*
* Copyright 2002-201
8
the original author or authors.
* Copyright 2002-201
9
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.
...
...
@@ -80,7 +80,9 @@ public abstract class AbstractWebArgumentResolverAdapter implements HandlerMetho
}
catch
(
Exception
ex
)
{
// ignore (see class-level doc)
logger
.
debug
(
"Error in checking support for parameter ["
+
parameter
+
"], message: "
+
ex
.
getMessage
());
if
(
logger
.
isDebugEnabled
())
{
logger
.
debug
(
"Error in checking support for parameter ["
+
parameter
+
"]: "
+
ex
.
getMessage
());
}
return
false
;
}
}
...
...
spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerExceptionResolver.java
浏览文件 @
1f4ca61b
/*
* Copyright 2002-201
8
the original author or authors.
* Copyright 2002-201
9
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.
...
...
@@ -99,7 +99,6 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti
* <p>Default is no warn logging. Specify this setting to activate warn logging into a specific
* category. Alternatively, override the {@link #logException} method for custom logging.
* @see org.apache.commons.logging.LogFactory#getLog(String)
* @see org.apache.log4j.Logger#getLogger(String)
* @see java.util.logging.Logger#getLogger(String)
*/
public
void
setWarnLogCategory
(
String
loggerName
)
{
...
...
@@ -131,11 +130,11 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti
prepareResponse
(
ex
,
response
);
ModelAndView
result
=
doResolveException
(
request
,
response
,
handler
,
ex
);
if
(
result
!=
null
)
{
// Print
warn message when warn logger is not enabled..
.
// Print
debug message when warn logger is not enabled
.
if
(
logger
.
isDebugEnabled
()
&&
(
this
.
warnLogger
==
null
||
!
this
.
warnLogger
.
isWarnEnabled
()))
{
logger
.
debug
(
"Resolved ["
+
ex
+
"]"
+
(
result
.
isEmpty
()
?
""
:
" to "
+
result
));
}
//
warnLogger with full stack trace (requires explicit config)
//
Explicitly configured warn logger in logException method.
logException
(
ex
,
request
);
}
return
result
;
...
...
spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/CookieLocaleResolver.java
浏览文件 @
1f4ca61b
/*
* Copyright 2002-201
7
the original author or authors.
* Copyright 2002-201
9
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.
...
...
@@ -55,7 +55,7 @@ import org.springframework.web.util.WebUtils;
public
class
CookieLocaleResolver
extends
CookieGenerator
implements
LocaleContextResolver
{
/**
* The name of the request attribute that holds the
Locale
.
* The name of the request attribute that holds the
{@code Locale}
.
* <p>Only used for overriding a cookie value if the locale has been
* changed in the course of the current request!
* <p>Use {@code RequestContext(Utils).getLocale()}
...
...
@@ -66,7 +66,7 @@ public class CookieLocaleResolver extends CookieGenerator implements LocaleConte
public
static
final
String
LOCALE_REQUEST_ATTRIBUTE_NAME
=
CookieLocaleResolver
.
class
.
getName
()
+
".LOCALE"
;
/**
* The name of the request attribute that holds the
TimeZone
.
* The name of the request attribute that holds the
{@code TimeZone}
.
* <p>Only used for overriding a cookie value if the locale has been
* changed in the course of the current request!
* <p>Use {@code RequestContext(Utils).getTimeZone()}
...
...
@@ -122,14 +122,14 @@ public class CookieLocaleResolver extends CookieGenerator implements LocaleConte
}
/**
* Set a fixed
L
ocale that this resolver will return if no cookie found.
* Set a fixed
l
ocale that this resolver will return if no cookie found.
*/
public
void
setDefaultLocale
(
Locale
defaultLocale
)
{
this
.
defaultLocale
=
defaultLocale
;
}
/**
* Return the fixed
L
ocale that this resolver will return if no cookie found,
* Return the fixed
l
ocale that this resolver will return if no cookie found,
* if any.
*/
protected
Locale
getDefaultLocale
()
{
...
...
@@ -137,7 +137,7 @@ public class CookieLocaleResolver extends CookieGenerator implements LocaleConte
}
/**
* Set a fixed
TimeZ
one that this resolver will return if no cookie found.
* Set a fixed
time z
one that this resolver will return if no cookie found.
* @since 4.0
*/
public
void
setDefaultTimeZone
(
TimeZone
defaultTimeZone
)
{
...
...
@@ -145,7 +145,7 @@ public class CookieLocaleResolver extends CookieGenerator implements LocaleConte
}
/**
* Return the fixed
TimeZ
one that this resolver will return if no cookie found,
* Return the fixed
time z
one that this resolver will return if no cookie found,
* if any.
* @since 4.0
*/
...
...
@@ -177,10 +177,11 @@ public class CookieLocaleResolver extends CookieGenerator implements LocaleConte
private
void
parseLocaleCookieIfNecessary
(
HttpServletRequest
request
)
{
if
(
request
.
getAttribute
(
LOCALE_REQUEST_ATTRIBUTE_NAME
)
==
null
)
{
// Retrieve and parse cookie value.
Cookie
cookie
=
WebUtils
.
getCookie
(
request
,
getCookieName
());
Locale
locale
=
null
;
TimeZone
timeZone
=
null
;
// Retrieve and parse cookie value.
Cookie
cookie
=
WebUtils
.
getCookie
(
request
,
getCookieName
());
if
(
cookie
!=
null
)
{
String
value
=
cookie
.
getValue
();
String
localePart
=
value
;
...
...
@@ -214,6 +215,7 @@ public class CookieLocaleResolver extends CookieGenerator implements LocaleConte
"'"
+
(
timeZone
!=
null
?
" and time zone '"
+
timeZone
.
getID
()
+
"'"
:
""
));
}
}
request
.
setAttribute
(
LOCALE_REQUEST_ATTRIBUTE_NAME
,
(
locale
!=
null
?
locale
:
determineDefaultLocale
(
request
)));
request
.
setAttribute
(
TIME_ZONE_REQUEST_ATTRIBUTE_NAME
,
...
...
@@ -296,7 +298,7 @@ public class CookieLocaleResolver extends CookieGenerator implements LocaleConte
/**
* Determine the default time zone for the given request,
* Called if no
TimeZ
one cookie has been found.
* Called if no
time z
one cookie has been found.
* <p>The default implementation returns the specified default time zone,
* if any, or {@code null} otherwise.
* @param request the request to resolve the time zone for
...
...
spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/LocaleChangeInterceptor.java
浏览文件 @
1f4ca61b
/*
* Copyright 2002-201
5
the original author or authors.
* Copyright 2002-201
9
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.
...
...
@@ -149,7 +149,9 @@ public class LocaleChangeInterceptor extends HandlerInterceptorAdapter {
}
catch
(
IllegalArgumentException
ex
)
{
if
(
isIgnoreInvalidLocale
())
{
logger
.
debug
(
"Ignoring invalid locale value ["
+
newLocale
+
"]: "
+
ex
.
getMessage
());
if
(
logger
.
isDebugEnabled
())
{
logger
.
debug
(
"Ignoring invalid locale value ["
+
newLocale
+
"]: "
+
ex
.
getMessage
());
}
}
else
{
throw
ex
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录