Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
f953fd5b
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,发现更多精彩内容 >>
提交
f953fd5b
编写于
3月 07, 2009
作者:
C
Chris Beams
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
+ Further documentation and pruning.
+ Added testing-related TODOs where appropriate
上级
31303512
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
48 addition
and
64 deletion
+48
-64
org.springframework.config.java/src/main/java/org/springframework/config/java/Bean.java
...a/src/main/java/org/springframework/config/java/Bean.java
+5
-1
org.springframework.config.java/src/main/java/org/springframework/config/java/Configuration.java
...n/java/org/springframework/config/java/Configuration.java
+5
-4
org.springframework.config.java/src/main/java/org/springframework/config/java/StandardScopes.java
.../java/org/springframework/config/java/StandardScopes.java
+2
-0
org.springframework.config.java/src/main/java/org/springframework/config/java/support/AbstractMethodInterceptor.java
...mework/config/java/support/AbstractMethodInterceptor.java
+0
-48
org.springframework.config.java/src/main/java/org/springframework/config/java/support/BeanMethodInterceptor.java
...gframework/config/java/support/BeanMethodInterceptor.java
+36
-11
未找到文件。
org.springframework.config.java/src/main/java/org/springframework/config/java/Bean.java
浏览文件 @
f953fd5b
...
...
@@ -54,7 +54,6 @@ import org.springframework.context.annotation.Scope;
* that references between beans are strongly typed and navigable. So called 'inter-bean
* references' are guaranteed to respect scoping and AOP semantics.
*
*
* @author Rod Johnson
* @author Costin Leau
* @author Chris Beams
...
...
@@ -97,3 +96,8 @@ public @interface Bean {
}
// TODO: test @Lazy @Bean
// TODO: test @Primary @Bean
// TODO: test Bean alias scenarios
// TODO: test init/destroy method scenarios
// TODO: test dependsOn
org.springframework.config.java/src/main/java/org/springframework/config/java/Configuration.java
浏览文件 @
f953fd5b
...
...
@@ -48,9 +48,6 @@ import org.springframework.stereotype.Component;
* {@link Autowired} constructor
* </ul>
*
* TODO: test constructor autowiring<br>
* TODO: test private Configuration classes<br>
* TODO: test @Lazy @Configuration<br>
*
* @author Rod Johnson
* @author Chris Beams
...
...
@@ -66,4 +63,8 @@ import org.springframework.stereotype.Component;
@Documented
public
@interface
Configuration
{
}
\ No newline at end of file
}
// TODO: test constructor autowiring<br>
// TODO: test private Configuration classes<br>
// TODO: test @Lazy @Configuration<br>
org.springframework.config.java/src/main/java/org/springframework/config/java/StandardScopes.java
浏览文件 @
f953fd5b
...
...
@@ -39,3 +39,5 @@ public class StandardScopes {
public
static
final
String
SESSION
=
"session"
;
}
// TODO: move StandardScopes to appropriate package
org.springframework.config.java/src/main/java/org/springframework/config/java/support/AbstractMethodInterceptor.java
已删除
100644 → 0
浏览文件 @
31303512
/*
* Copyright 2002-2008 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.config.java.support
;
import
java.lang.reflect.Method
;
import
net.sf.cglib.proxy.MethodInterceptor
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.factory.BeanFactory
;
import
org.springframework.beans.factory.BeanFactoryAware
;
import
org.springframework.beans.factory.support.DefaultListableBeanFactory
;
import
org.springframework.util.Assert
;
/**
* Base class for all {@link MethodInterceptor} implementations.
*
* @author Chris Beams
*/
abstract
class
AbstractMethodInterceptor
implements
BeanFactoryAware
,
MethodInterceptor
{
protected
final
Log
log
=
LogFactory
.
getLog
(
this
.
getClass
());
protected
DefaultListableBeanFactory
beanFactory
;
public
void
setBeanFactory
(
BeanFactory
beanFactory
)
throws
BeansException
{
Assert
.
isInstanceOf
(
DefaultListableBeanFactory
.
class
,
beanFactory
);
this
.
beanFactory
=
(
DefaultListableBeanFactory
)
beanFactory
;
}
protected
String
getBeanName
(
Method
method
)
{
return
method
.
getName
();
}
}
org.springframework.config.java/src/main/java/org/springframework/config/java/support/BeanMethodInterceptor.java
浏览文件 @
f953fd5b
/*
* Copyright 2002-200
8
the original author or authors.
* Copyright 2002-200
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.
...
...
@@ -19,41 +19,66 @@ import static java.lang.String.*;
import
java.lang.reflect.Method
;
import
net.sf.cglib.proxy.MethodInterceptor
;
import
net.sf.cglib.proxy.MethodProxy
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.factory.BeanFactory
;
import
org.springframework.beans.factory.BeanFactoryAware
;
import
org.springframework.beans.factory.config.ConfigurableBeanFactory
;
import
org.springframework.beans.factory.support.DefaultListableBeanFactory
;
import
org.springframework.config.java.Bean
;
import
org.springframework.context.annotation.Scope
;
import
org.springframework.context.annotation.ScopedProxyMode
;
import
org.springframework.core.annotation.AnnotationUtils
;
import
org.springframework.util.Assert
;
/**
* Intercepts the invocation of any {@link Bean}-annotated methods in order to ensure proper
* handling of bean semantics such as scoping and AOP proxying.
*
* @author Chris Beams
* @since 3.0
* @see Bean
* @see BeanRegistrar
*
* @author Chris Beams
*/
class
BeanMethodInterceptor
extends
AbstractMethodInterceptor
{
class
BeanMethodInterceptor
implements
BeanFactoryAware
,
MethodInterceptor
{
protected
final
Log
log
=
LogFactory
.
getLog
(
this
.
getClass
());
protected
DefaultListableBeanFactory
beanFactory
;
public
void
setBeanFactory
(
BeanFactory
beanFactory
)
throws
BeansException
{
Assert
.
isInstanceOf
(
DefaultListableBeanFactory
.
class
,
beanFactory
);
this
.
beanFactory
=
(
DefaultListableBeanFactory
)
beanFactory
;
}
/**
* Enhances a {@link Bean @Bean} method to check the supplied BeanFactory for the
* existence of this bean object.
*/
public
Object
intercept
(
Object
obj
,
Method
method
,
Object
[]
args
,
MethodProxy
proxy
)
throws
Throwable
{
String
beanName
=
getBeanName
(
method
);
// determine the name of the bean
String
beanName
;
// check to see if the user has explicitly set the bean name
Bean
bean
=
method
.
getAnnotation
(
Bean
.
class
);
if
(
bean
!=
null
&&
bean
.
name
().
length
>
1
)
beanName
=
bean
.
name
()[
0
];
// if not, simply return the name of the method as the bean name
else
beanName
=
method
.
getName
();
// determine whether this bean is a scoped-proxy
Scope
scope
=
AnnotationUtils
.
findAnnotation
(
method
,
Scope
.
class
);
boolean
isScopedProxy
=
(
scope
!=
null
&&
scope
.
proxyMode
()
!=
ScopedProxyMode
.
NO
);
String
scopedBeanName
=
BeanRegistrar
.
resolveHiddenScopedProxyBeanName
(
beanName
);
if
(
isScopedProxy
&&
beanFactory
.
isCurrentlyInCreation
(
scopedBeanName
))
beanName
=
scopedBeanName
;
String
scopedBeanName
=
BeanRegistrar
.
resolveHiddenScopedProxyBeanName
(
beanName
);
if
(
isScopedProxy
&&
beanFactory
.
isCurrentlyInCreation
(
scopedBeanName
))
beanName
=
scopedBeanName
;
// to handle the case of an inter-bean method reference, we must explicitly check the
// container for already cached instances
if
(
factoryContainsBean
(
beanName
))
{
// we have an already existing cached instance of this bean -> retrieve it
Object
cachedBean
=
beanFactory
.
getBean
(
beanName
);
...
...
@@ -64,6 +89,7 @@ class BeanMethodInterceptor extends AbstractMethodInterceptor {
return
cachedBean
;
}
// actually create and return the bean
return
proxy
.
invokeSuper
(
obj
,
args
);
}
...
...
@@ -87,5 +113,4 @@ class BeanMethodInterceptor extends AbstractMethodInterceptor {
return
beanFactory
.
containsBean
(
beanName
)
&&
!
beanFactory
.
isCurrentlyInCreation
(
beanName
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录