Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
chenpeng_fei
spring-framework
提交
eeeab27f
S
spring-framework
项目概览
chenpeng_fei
/
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,发现更多精彩内容 >>
提交
eeeab27f
编写于
8月 10, 2016
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polishing
(cherry picked from commit
35e247aa
)
上级
2a4ee07c
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
48 addition
and
48 deletion
+48
-48
spring-messaging/src/main/java/org/springframework/messaging/simp/user/MultiServerUserRegistry.java
...ramework/messaging/simp/user/MultiServerUserRegistry.java
+3
-3
spring-test/src/main/java/org/springframework/test/context/jdbc/SqlScriptsTestExecutionListener.java
...rk/test/context/jdbc/SqlScriptsTestExecutionListener.java
+27
-39
spring-test/src/main/java/org/springframework/test/context/support/ActiveProfilesUtils.java
...ngframework/test/context/support/ActiveProfilesUtils.java
+3
-3
spring-test/src/main/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilder.java
...st/web/servlet/request/MockHttpServletRequestBuilder.java
+3
-3
spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ResourceHandlerRegistry.java
...eb/servlet/config/annotation/ResourceHandlerRegistry.java
+12
-0
未找到文件。
spring-messaging/src/main/java/org/springframework/messaging/simp/user/MultiServerUserRegistry.java
浏览文件 @
eeeab27f
...
...
@@ -174,7 +174,7 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati
@Override
public
String
toString
()
{
return
"local=["
+
this
.
localRegistry
+
"], remote="
+
this
.
remoteRegistries
+
"]"
;
return
"local=["
+
this
.
localRegistry
+
"], remote="
+
this
.
remoteRegistries
;
}
...
...
@@ -260,7 +260,6 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati
/**
* SimpUser that can be (de)serialized and broadcast to other servers.
*/
@SuppressWarnings
(
"unused"
)
private
static
class
TransferSimpUser
implements
SimpUser
{
private
String
name
;
...
...
@@ -274,6 +273,7 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati
/**
* Default constructor for JSON deserialization.
*/
@SuppressWarnings
(
"unused"
)
public
TransferSimpUser
()
{
this
.
sessions
=
new
HashSet
<>(
1
);
}
...
...
@@ -368,7 +368,6 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati
/**
* SimpSession that can be (de)serialized and broadcast to other servers.
*/
@SuppressWarnings
(
"unused"
)
private
static
class
TransferSimpSession
implements
SimpSession
{
private
String
id
;
...
...
@@ -380,6 +379,7 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati
/**
* Default constructor for JSON deserialization.
*/
@SuppressWarnings
(
"unused"
)
public
TransferSimpSession
()
{
this
.
subscriptions
=
new
HashSet
<>(
4
);
}
...
...
spring-test/src/main/java/org/springframework/test/context/jdbc/SqlScriptsTestExecutionListener.java
浏览文件 @
eeeab27f
...
...
@@ -127,11 +127,11 @@ public class SqlScriptsTestExecutionListener extends AbstractTestExecutionListen
private
void
executeSqlScripts
(
TestContext
testContext
,
ExecutionPhase
executionPhase
)
throws
Exception
{
boolean
classLevel
=
false
;
Set
<
Sql
>
sqlAnnotations
=
AnnotatedElementUtils
.
getMergedRepeatableAnnotations
(
testContext
.
getTestMethod
(),
Sql
.
class
,
SqlGroup
.
class
);
Set
<
Sql
>
sqlAnnotations
=
AnnotatedElementUtils
.
getMergedRepeatableAnnotations
(
testContext
.
getTestMethod
(),
Sql
.
class
,
SqlGroup
.
class
);
if
(
sqlAnnotations
.
isEmpty
())
{
sqlAnnotations
=
AnnotatedElementUtils
.
getMergedRepeatableAnnotations
(
testContext
.
getTestClass
(),
Sql
.
class
,
SqlGroup
.
class
);
sqlAnnotations
=
AnnotatedElementUtils
.
getMergedRepeatableAnnotations
(
testContext
.
getTestClass
(),
Sql
.
class
,
SqlGroup
.
class
);
if
(!
sqlAnnotations
.
isEmpty
())
{
classLevel
=
true
;
}
...
...
@@ -145,26 +145,24 @@ public class SqlScriptsTestExecutionListener extends AbstractTestExecutionListen
/**
* Execute the SQL scripts configured via the supplied {@link Sql @Sql}
* annotation for the given {@link ExecutionPhase} and {@link TestContext}.
*
* <p>Special care must be taken in order to properly support the configured
* {@link SqlConfig#transactionMode}.
*
* @param sql the {@code @Sql} annotation to parse
* @param executionPhase the current execution phase
* @param testContext the current {@code TestContext}
* @param classLevel {@code true} if {@link Sql @Sql} was declared at the
* class level
* @param classLevel {@code true} if {@link Sql @Sql} was declared at the class level
*/
private
void
executeSqlScripts
(
Sql
sql
,
ExecutionPhase
executionPhase
,
TestContext
testContext
,
boolean
classLevel
)
throws
Exception
{
if
(
executionPhase
!=
sql
.
executionPhase
())
{
return
;
}
MergedSqlConfig
mergedSqlConfig
=
new
MergedSqlConfig
(
sql
.
config
(),
testContext
.
getTestClass
());
if
(
logger
.
isDebugEnabled
())
{
logger
.
debug
(
String
.
format
(
"Processing %s for execution phase [%s] and test context %s."
,
mergedSqlConfig
,
executionPhase
,
testContext
));
logger
.
debug
(
String
.
format
(
"Processing %s for execution phase [%s] and test context %s."
,
mergedSqlConfig
,
executionPhase
,
testContext
));
}
final
ResourceDatabasePopulator
populator
=
new
ResourceDatabasePopulator
();
...
...
@@ -179,15 +177,13 @@ public class SqlScriptsTestExecutionListener extends AbstractTestExecutionListen
String
[]
scripts
=
getScripts
(
sql
,
testContext
,
classLevel
);
scripts
=
TestContextResourceUtils
.
convertToClasspathResourcePaths
(
testContext
.
getTestClass
(),
scripts
);
List
<
Resource
>
scriptResources
=
TestContextResourceUtils
.
convertToResourceList
(
testContext
.
getApplicationContext
(),
scripts
);
for
(
String
statement
:
sql
.
statements
())
{
if
(
StringUtils
.
hasText
(
statement
))
{
statement
=
statement
.
trim
();
scriptResources
.
add
(
new
ByteArrayResource
(
statement
.
getBytes
(),
"from inlined SQL statement: "
+
statement
));
testContext
.
getApplicationContext
(),
scripts
);
for
(
String
stmt
:
sql
.
statements
())
{
if
(
StringUtils
.
hasText
(
stmt
))
{
stmt
=
stmt
.
trim
();
scriptResources
.
add
(
new
ByteArrayResource
(
stmt
.
getBytes
(),
"from inlined SQL statement: "
+
stmt
));
}
}
populator
.
setScripts
(
scriptResources
.
toArray
(
new
Resource
[
scriptResources
.
size
()]));
if
(
logger
.
isDebugEnabled
())
{
logger
.
debug
(
"Executing SQL scripts: "
+
ObjectUtils
.
nullSafeToString
(
scriptResources
));
...
...
@@ -196,47 +192,39 @@ public class SqlScriptsTestExecutionListener extends AbstractTestExecutionListen
String
dsName
=
mergedSqlConfig
.
getDataSource
();
String
tmName
=
mergedSqlConfig
.
getTransactionManager
();
DataSource
dataSource
=
TestContextTransactionUtils
.
retrieveDataSource
(
testContext
,
dsName
);
final
PlatformTransactionManager
transactionManager
=
TestContextTransactionUtils
.
retrieveTransactionManager
(
testContext
,
tmName
);
final
boolean
newTxRequired
=
mergedSqlConfig
.
getTransactionMode
()
==
TransactionMode
.
ISOLATED
;
PlatformTransactionManager
txMgr
=
TestContextTransactionUtils
.
retrieveTransactionManager
(
testContext
,
tmName
);
boolean
newTxRequired
=
(
mergedSqlConfig
.
getTransactionMode
()
==
TransactionMode
.
ISOLATED
);
if
(
t
ransactionManage
r
==
null
)
{
if
(
t
xMg
r
==
null
)
{
Assert
.
state
(!
newTxRequired
,
()
->
String
.
format
(
"Failed to execute SQL scripts for test context %s: "
+
"cannot execute SQL scripts using Transaction Mode "
+
"[%s] without a PlatformTransactionManager."
,
testContext
,
TransactionMode
.
ISOLATED
));
Assert
.
state
(
dataSource
!=
null
,
()
->
String
.
format
(
"Failed to execute SQL scripts for test context %s: "
+
"supply at least a DataSource or PlatformTransactionManager."
,
testContext
));
// Execute scripts directly against the DataSource
populator
.
execute
(
dataSource
);
}
else
{
DataSource
dataSourceFromTxMgr
=
getDataSourceFromTransactionManager
(
transactionManager
);
DataSource
dataSourceFromTxMgr
=
getDataSourceFromTransactionManager
(
txMgr
);
// Ensure user configured an appropriate DataSource/TransactionManager pair.
if
(
dataSource
!=
null
&&
dataSourceFromTxMgr
!=
null
&&
!
dataSource
.
equals
(
dataSourceFromTxMgr
))
{
throw
new
IllegalStateException
(
String
.
format
(
"Failed to execute SQL scripts for test context %s: "
+
"the configured DataSource [%s] (named '%s') is not the one associated with "
+
"transaction manager [%s] (named '%s')."
,
testContext
,
dataSource
.
getClass
().
getName
(),
dsName
,
transactionManage
r
.
getClass
().
getName
(),
tmName
));
dsName
,
txMg
r
.
getClass
().
getName
(),
tmName
));
}
if
(
dataSource
==
null
)
{
dataSource
=
dataSourceFromTxMgr
;
Assert
.
state
(
dataSource
!=
null
,
()
->
String
.
format
(
"Failed to execute SQL scripts for
test context %s:
"
+
"
could not obtain DataSource from transaction manager [%s] (named '%s')."
,
testContext
,
t
ransactionManage
r
.
getClass
().
getName
(),
tmName
));
Assert
.
state
(
dataSource
!=
null
,
()
->
String
.
format
(
"Failed to execute SQL scripts for "
+
"
test context %s: could not obtain DataSource from transaction manager [%s] (named '%s')."
,
t
estContext
,
txMg
r
.
getClass
().
getName
(),
tmName
));
}
final
DataSource
finalDataSource
=
dataSource
;
int
propagation
=
(
newTxRequired
?
TransactionDefinition
.
PROPAGATION_REQUIRES_NEW
:
TransactionDefinition
.
PROPAGATION_REQUIRED
);
TransactionAttribute
transactionAttribute
=
TestContextTransactionUtils
.
createDelegatingTransactionAttribute
(
testContext
,
new
DefaultTransactionAttribute
(
propagation
));
new
TransactionTemplate
(
transactionManager
,
transactionAttribute
).
execute
(
status
->
{
TransactionAttribute
txAttr
=
TestContextTransactionUtils
.
createDelegatingTransactionAttribute
(
testContext
,
new
DefaultTransactionAttribute
(
propagation
));
new
TransactionTemplate
(
txMgr
,
txAttr
).
execute
(
status
->
{
populator
.
execute
(
finalDataSource
);
return
null
;
});
...
...
@@ -260,7 +248,7 @@ public class SqlScriptsTestExecutionListener extends AbstractTestExecutionListen
private
String
[]
getScripts
(
Sql
sql
,
TestContext
testContext
,
boolean
classLevel
)
{
String
[]
scripts
=
sql
.
scripts
();
if
(
ObjectUtils
.
isEmpty
(
scripts
)
&&
ObjectUtils
.
isEmpty
(
sql
.
statements
()))
{
scripts
=
new
String
[]
{
detectDefaultScript
(
testContext
,
classLevel
)
};
scripts
=
new
String
[]
{
detectDefaultScript
(
testContext
,
classLevel
)
};
}
return
scripts
;
}
...
...
@@ -286,8 +274,8 @@ public class SqlScriptsTestExecutionListener extends AbstractTestExecutionListen
if
(
classPathResource
.
exists
())
{
if
(
logger
.
isInfoEnabled
())
{
logger
.
info
(
String
.
format
(
"Detected default SQL script \"%s\" for test %s [%s]"
,
prefixedResourcePath
,
elementType
,
elementName
));
logger
.
info
(
String
.
format
(
"Detected default SQL script \"%s\" for test %s [%s]"
,
prefixedResourcePath
,
elementType
,
elementName
));
}
return
prefixedResourcePath
;
}
...
...
spring-test/src/main/java/org/springframework/test/context/support/ActiveProfilesUtils.java
浏览文件 @
eeeab27f
...
...
@@ -86,7 +86,7 @@ abstract class ActiveProfilesUtils {
ActiveProfiles
annotation
=
descriptor
.
synthesizeAnnotation
();
if
(
logger
.
isTraceEnabled
())
{
logger
.
trace
(
String
.
format
(
"Retrieved @ActiveProfiles [%s] for declaring class [%s]
.
"
,
logger
.
trace
(
String
.
format
(
"Retrieved @ActiveProfiles [%s] for declaring class [%s]"
,
annotation
,
declaringClass
.
getName
()));
}
...
...
@@ -101,7 +101,7 @@ abstract class ActiveProfilesUtils {
}
catch
(
Exception
ex
)
{
String
msg
=
String
.
format
(
"Could not instantiate ActiveProfilesResolver of type [%s] "
+
"for test class [%s]
.
"
,
resolverClass
.
getName
(),
rootDeclaringClass
.
getName
());
"for test class [%s]"
,
resolverClass
.
getName
(),
rootDeclaringClass
.
getName
());
logger
.
error
(
msg
);
throw
new
IllegalStateException
(
msg
,
ex
);
}
...
...
@@ -109,7 +109,7 @@ abstract class ActiveProfilesUtils {
String
[]
profiles
=
resolver
.
resolve
(
rootDeclaringClass
);
if
(
profiles
==
null
)
{
String
msg
=
String
.
format
(
"ActiveProfilesResolver [%s] returned a null array of bean definition profiles
.
"
,
"ActiveProfilesResolver [%s] returned a null array of bean definition profiles"
,
resolverClass
.
getName
());
logger
.
error
(
msg
);
throw
new
IllegalStateException
(
msg
);
...
...
spring-test/src/main/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilder.java
浏览文件 @
eeeab27f
...
...
@@ -240,7 +240,7 @@ public class MockHttpServletRequestBuilder
* @param mediaTypes one or more media types
*/
public
MockHttpServletRequestBuilder
accept
(
MediaType
...
mediaTypes
)
{
Assert
.
notEmpty
(
mediaTypes
,
"
No 'Accept' media types
"
);
Assert
.
notEmpty
(
mediaTypes
,
"
'mediaTypes' must not be empty
"
);
this
.
headers
.
set
(
"Accept"
,
MediaType
.
toString
(
Arrays
.
asList
(
mediaTypes
)));
return
this
;
}
...
...
@@ -250,8 +250,8 @@ public class MockHttpServletRequestBuilder
* @param mediaTypes one or more media types
*/
public
MockHttpServletRequestBuilder
accept
(
String
...
mediaTypes
)
{
Assert
.
notEmpty
(
mediaTypes
,
"
No 'Accept' media types
"
);
List
<
MediaType
>
result
=
new
ArrayList
<>(
mediaTypes
.
length
);
Assert
.
notEmpty
(
mediaTypes
,
"
'mediaTypes' must not be empty
"
);
List
<
MediaType
>
result
=
new
ArrayList
<
MediaType
>(
mediaTypes
.
length
);
for
(
String
mediaType
:
mediaTypes
)
{
result
.
add
(
MediaType
.
parseMediaType
(
mediaType
));
}
...
...
spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ResourceHandlerRegistry.java
浏览文件 @
eeeab27f
...
...
@@ -62,10 +62,22 @@ public class ResourceHandlerRegistry {
private
int
order
=
Integer
.
MAX_VALUE
-
1
;
/**
* Create a new resource handler registry for the given application context.
* @param applicationContext the Spring application context
* @param servletContext the corresponding Servlet context
*/
public
ResourceHandlerRegistry
(
ApplicationContext
applicationContext
,
ServletContext
servletContext
)
{
this
(
applicationContext
,
servletContext
,
null
);
}
/**
* Create a new resource handler registry for the given application context.
* @param applicationContext the Spring application context
* @param servletContext the corresponding Servlet context
* @param contentNegotiationManager the content negotiation manager to use
* @since 4.3
*/
public
ResourceHandlerRegistry
(
ApplicationContext
applicationContext
,
ServletContext
servletContext
,
ContentNegotiationManager
contentNegotiationManager
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录