Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
ff675f52
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 搜索 >>
提交
ff675f52
编写于
12月 26, 2016
作者:
S
Sebastien Deleuze
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add Kotlin extensions for bean registration and retrieval
Issue: SPR-15048
上级
a8741dd3
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
187 addition
and
5 deletion
+187
-5
build.gradle
build.gradle
+10
-5
spring-beans/src/main/kotlin/org/springframework/beans/factory/BeanFactoryExtension.kt
...org/springframework/beans/factory/BeanFactoryExtension.kt
+29
-0
spring-beans/src/main/kotlin/org/springframework/beans/factory/ListableBeanFactoryExtension.kt
...ngframework/beans/factory/ListableBeanFactoryExtension.kt
+56
-0
spring-context/src/main/kotlin/org/springframework/context/support/GenericApplicationContextExtension.kt
...ork/context/support/GenericApplicationContextExtension.kt
+47
-0
spring-context/src/test/kotlin/org/springframework/context/support/GenericApplicationContextExtensionTests.kt
...ontext/support/GenericApplicationContextExtensionTests.kt
+45
-0
未找到文件。
build.gradle
浏览文件 @
ff675f52
...
...
@@ -326,7 +326,7 @@ project("spring-build-src") {
project
(
"spring-core"
)
{
description
=
"Spring Core"
// Kotlin compiler does not support JDK 9 yet
// Kotlin compiler does not support JDK 9 yet
, see https://youtrack.jetbrains.com/issue/KT-14988
if
(!
JavaVersion
.
current
().
java9Compatible
)
{
apply
plugin:
"kotlin"
}
...
...
@@ -430,7 +430,7 @@ project("spring-core") {
project
(
"spring-beans"
)
{
description
=
"Spring Beans"
// Kotlin compiler does not support JDK 9 yet
// Kotlin compiler does not support JDK 9 yet
, see https://youtrack.jetbrains.com/issue/KT-14988
if
(!
JavaVersion
.
current
().
java9Compatible
)
{
apply
plugin:
"kotlin"
}
...
...
@@ -514,6 +514,10 @@ project("spring-context") {
description
=
"Spring Context"
apply
plugin:
"groovy"
// Kotlin compiler does not support JDK 9 yet, see https://youtrack.jetbrains.com/issue/KT-14988
if
(!
JavaVersion
.
current
().
java9Compatible
)
{
apply
plugin:
"kotlin"
}
dependencies
{
compile
(
project
(
":spring-aop"
))
...
...
@@ -536,6 +540,7 @@ project("spring-context") {
optional
(
"org.aspectj:aspectjweaver:${aspectjVersion}"
)
optional
(
"org.codehaus.groovy:groovy-all:${groovyVersion}"
)
optional
(
"org.beanshell:bsh:2.0b4"
)
optional
(
"org.jetbrains.kotlin:kotlin-stdlib:${kotlinVersion}"
)
testCompile
(
"org.apache.commons:commons-pool2:2.4.2"
)
testCompile
(
"org.slf4j:slf4j-api:${slf4jVersion}"
)
testCompile
(
"javax.inject:javax.inject-tck:1"
)
...
...
@@ -581,7 +586,7 @@ project("spring-oxm") {
project
(
"spring-messaging"
)
{
description
=
"Spring Messaging"
// Kotlin compiler does not support JDK 9 yet
// Kotlin compiler does not support JDK 9 yet
, see https://youtrack.jetbrains.com/issue/KT-14988
if
(!
JavaVersion
.
current
().
java9Compatible
)
{
apply
plugin:
"kotlin"
}
...
...
@@ -726,7 +731,7 @@ project("spring-context-indexer") {
project
(
"spring-web"
)
{
description
=
"Spring Web"
// Kotlin compiler does not support JDK 9 yet
// Kotlin compiler does not support JDK 9 yet
, see https://youtrack.jetbrains.com/issue/KT-14988
if
(!
JavaVersion
.
current
().
java9Compatible
)
{
apply
plugin:
"kotlin"
}
...
...
@@ -819,7 +824,7 @@ project("spring-web") {
project
(
"spring-web-reactive"
)
{
description
=
"Spring Web Reactive"
// Kotlin compiler does not support JDK 9 yet
// Kotlin compiler does not support JDK 9 yet
, see https://youtrack.jetbrains.com/issue/KT-14988
if
(!
JavaVersion
.
current
().
java9Compatible
)
{
apply
plugin:
"kotlin"
}
...
...
spring-beans/src/main/kotlin/org/springframework/beans/factory/BeanFactoryExtension.kt
0 → 100644
浏览文件 @
ff675f52
package
org.springframework.beans.factory
import
kotlin.reflect.KClass
/**
* Extension for [BeanFactory] providing [KClass] based API.
*
* @since 5.0
*/
object
BeanFactoryExtension
{
/**
* @see BeanFactory.getBean(Class<T>)
*/
fun
<
T
:
Any
>
BeanFactory
.
getBean
(
requiredType
:
KClass
<
T
>)
=
getBean
(
requiredType
.
java
)
/**
* @see BeanFactory.getBean(String, Class<T>)
*/
fun
<
T
:
Any
>
BeanFactory
.
getBean
(
name
:
String
,
requiredType
:
KClass
<
T
>)
=
getBean
(
name
,
requiredType
.
java
)
/**
* @see BeanFactory.getBean(Class<T>, Object...)
*/
fun
<
T
:
Any
>
BeanFactory
.
getBean
(
requiredType
:
KClass
<
T
>,
vararg
args
:
Any
)
=
getBean
(
requiredType
.
java
,
*
args
)
}
spring-beans/src/main/kotlin/org/springframework/beans/factory/ListableBeanFactoryExtension.kt
0 → 100644
浏览文件 @
ff675f52
package
org.springframework.beans.factory
import
kotlin.reflect.KClass
/**
* Extension for [ListableBeanFactory] providing [KClass] based API.
*
* @since 5.0
*/
object
ListableBeanFactoryExtension
{
/**
* @see ListableBeanFactory.getBeanNamesForType(Class<?>)
*/
fun
<
T
:
Any
>
ListableBeanFactory
.
getBeanNamesForType
(
type
:
KClass
<
T
>)
=
getBeanNamesForType
(
type
.
java
)
/**
* @see ListableBeanFactory.getBeanNamesForType(Class<?>, boolean, boolean)
*/
fun
<
T
:
Any
>
ListableBeanFactory
.
getBeanNamesForType
(
type
:
KClass
<
T
>,
includeNonSingletons
:
Boolean
,
allowEagerInit
:
Boolean
)
=
getBeanNamesForType
(
type
.
java
,
includeNonSingletons
,
allowEagerInit
)
/**
* @see ListableBeanFactory.getBeansOfType(Class<T>)
*/
fun
<
T
:
Any
>
ListableBeanFactory
.
getBeansOfType
(
type
:
KClass
<
T
>)
=
getBeansOfType
(
type
.
java
)
/**
* @see ListableBeanFactory.getBeansOfType(Class<T>, boolean, boolean)
*/
fun
<
T
:
Any
>
ListableBeanFactory
.
getBeansOfType
(
type
:
KClass
<
T
>,
includeNonSingletons
:
Boolean
,
allowEagerInit
:
Boolean
)
=
getBeansOfType
(
type
.
java
,
includeNonSingletons
,
allowEagerInit
)
/**
* @see ListableBeanFactory.getBeanNamesForAnnotation
*/
fun
<
T
:
Annotation
>
ListableBeanFactory
.
getBeanNamesForAnnotation
(
type
:
KClass
<
T
>)
=
getBeanNamesForAnnotation
(
type
.
java
)
/**
* @see ListableBeanFactory.getBeansWithAnnotation
*/
fun
<
T
:
Annotation
>
ListableBeanFactory
.
getBeansWithAnnotation
(
type
:
KClass
<
T
>)
=
getBeansWithAnnotation
(
type
.
java
)
/**
* @see ListableBeanFactoryExtension.findAnnotationOnBean
*/
fun
<
T
:
Annotation
>
ListableBeanFactory
.
findAnnotationOnBean
(
beanName
:
String
,
type
:
KClass
<
T
>)
=
findAnnotationOnBean
(
beanName
,
type
.
java
)
}
spring-context/src/main/kotlin/org/springframework/context/support/GenericApplicationContextExtension.kt
0 → 100644
浏览文件 @
ff675f52
package
org.springframework.context.support
import
org.springframework.beans.factory.config.BeanDefinitionCustomizer
import
java.util.function.Supplier
import
kotlin.reflect.KClass
/**
* Extension for [GenericApplicationContext] providing [KClass] based API and
* avoiding specifying a class parameter for the [Supplier] based variant thanks to
* Kotlin reified type parameters.
*
* @since 5.0
*/
object
GenericApplicationContextExtension
{
/**
* @see GenericApplicationContext.registerBean(Class<T>, BeanDefinitionCustomizer...)
*/
fun
<
T
:
Any
>
GenericApplicationContext
.
registerBean
(
beanClass
:
KClass
<
T
>,
vararg
customizers
:
BeanDefinitionCustomizer
)
{
registerBean
(
beanClass
.
java
,
*
customizers
)
}
/**
* @see GenericApplicationContext.registerBean(String, Class<T>, BeanDefinitionCustomizer...)
*/
fun
<
T
:
Any
>
GenericApplicationContext
.
registerBean
(
beanName
:
String
,
beanClass
:
KClass
<
T
>,
vararg
customizers
:
BeanDefinitionCustomizer
)
{
registerBean
(
beanName
,
beanClass
.
java
,
*
customizers
)
}
/**
* @see GenericApplicationContext.registerBean(Class<T>, Supplier<T>, BeanDefinitionCustomizer...)
*/
inline
fun
<
reified
T
:
Any
>
GenericApplicationContext
.
registerBean
(
supplier
:
Supplier
<
T
>,
vararg
customizers
:
BeanDefinitionCustomizer
)
{
registerBean
(
T
::
class
.
java
,
supplier
,
*
customizers
)
}
/**
* @see GenericApplicationContext.registerBean(String, Class<T>, Supplier<T>, BeanDefinitionCustomizer...)
*/
inline
fun
<
reified
T
:
Any
>
GenericApplicationContext
.
registerBean
(
name
:
String
,
supplier
:
Supplier
<
T
>,
vararg
customizers
:
BeanDefinitionCustomizer
)
{
registerBean
(
name
,
T
::
class
.
java
,
supplier
,
*
customizers
)
}
}
spring-context/src/test/kotlin/org/springframework/context/support/GenericApplicationContextExtensionTests.kt
0 → 100644
浏览文件 @
ff675f52
package
org.springframework.context.support
import
org.junit.Assert.assertNotNull
import
org.junit.Test
import
org.springframework.context.support.GenericApplicationContextExtension.registerBean
import
org.springframework.beans.factory.BeanFactoryExtension.getBean
import
java.util.function.Supplier
class
GenericApplicationContextExtensionTests
{
@Test
fun
registerBeanWithClass
()
{
val
context
=
GenericApplicationContext
()
context
.
registerBean
(
BeanA
::
class
)
context
.
refresh
()
assertNotNull
(
context
.
getBean
(
BeanA
::
class
))
}
@Test
fun
registerBeanWithNameAndClass
()
{
val
context
=
GenericApplicationContext
()
context
.
registerBean
(
"a"
,
BeanA
::
class
)
context
.
refresh
()
assertNotNull
(
context
.
getBean
(
"a"
))
}
@Test
fun
registerBeanWithSupplier
()
{
val
context
=
GenericApplicationContext
()
context
.
registerBean
(
Supplier
{
BeanA
()
})
context
.
refresh
()
assertNotNull
(
context
.
getBean
(
BeanA
::
class
))
}
@Test
fun
registerBeanWithNameAndSupplier
()
{
val
context
=
GenericApplicationContext
()
context
.
registerBean
(
"a"
,
Supplier
{
BeanA
()
})
context
.
refresh
()
assertNotNull
(
context
.
getBean
(
"a"
))
}
internal
class
BeanA
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录