1
1
/*
2
- * Copyright 2002-2016 the original author or authors.
2
+ * Copyright 2002-2017 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
35
35
import org .springframework .core .ResolvableType ;
36
36
import org .springframework .core .annotation .AnnotationUtils ;
37
37
import org .springframework .util .Assert ;
38
+ import org .springframework .util .ObjectUtils ;
38
39
import org .springframework .util .StringUtils ;
39
40
40
41
/**
@@ -134,12 +135,21 @@ public Object getBean(String name) throws BeansException {
134
135
@ SuppressWarnings ("unchecked" )
135
136
public <T > T getBean (String name , Class <T > requiredType ) throws BeansException {
136
137
Object bean = getBean (name );
137
- if (requiredType != null && !requiredType .isAssignableFrom (bean . getClass () )) {
138
+ if (requiredType != null && !requiredType .isInstance (bean )) {
138
139
throw new BeanNotOfRequiredTypeException (name , requiredType , bean .getClass ());
139
140
}
140
141
return (T ) bean ;
141
142
}
142
143
144
+ @ Override
145
+ public Object getBean (String name , Object ... args ) throws BeansException {
146
+ if (!ObjectUtils .isEmpty (args )) {
147
+ throw new UnsupportedOperationException (
148
+ "StaticListableBeanFactory does not support explicit bean creation arguments" );
149
+ }
150
+ return getBean (name );
151
+ }
152
+
143
153
@ Override
144
154
public <T > T getBean (Class <T > requiredType ) throws BeansException {
145
155
String [] beanNames = getBeanNamesForType (requiredType );
@@ -154,18 +164,9 @@ else if (beanNames.length > 1) {
154
164
}
155
165
}
156
166
157
- @ Override
158
- public Object getBean (String name , Object ... args ) throws BeansException {
159
- if (args != null ) {
160
- throw new UnsupportedOperationException (
161
- "StaticListableBeanFactory does not support explicit bean creation arguments" );
162
- }
163
- return getBean (name );
164
- }
165
-
166
167
@ Override
167
168
public <T > T getBean (Class <T > requiredType , Object ... args ) throws BeansException {
168
- if (args != null ) {
169
+ if (! ObjectUtils . isEmpty ( args ) ) {
169
170
throw new UnsupportedOperationException (
170
171
"StaticListableBeanFactory does not support explicit bean creation arguments" );
171
172
}
@@ -352,7 +353,8 @@ public Map<String, Object> getBeansWithAnnotation(Class<? extends Annotation> an
352
353
public <A extends Annotation > A findAnnotationOnBean (String beanName , Class <A > annotationType )
353
354
throws NoSuchBeanDefinitionException {
354
355
355
- return AnnotationUtils .findAnnotation (getType (beanName ), annotationType );
356
+ Class <?> beanType = getType (beanName );
357
+ return (beanType != null ? AnnotationUtils .findAnnotation (beanType , annotationType ) : null );
356
358
}
357
359
358
360
}
0 commit comments