This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new f76bf4c camel-spring - Optimize when lookup bean by name to avoid
having spring throw an exception if not found, which we handle anyway by
returning null.
f76bf4c is described below
commit f76bf4c16c1745ce02fb4648f70f42e7ab5e5808
Author: Claus Ibsen <[email protected]>
AuthorDate: Mon Oct 5 13:44:21 2020 +0200
camel-spring - Optimize when lookup bean by name to avoid having spring
throw an exception if not found, which we handle anyway by returning null.
---
.../spring/spi/ApplicationContextBeanRepository.java | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git
a/components/camel-spring/src/main/java/org/apache/camel/spring/spi/ApplicationContextBeanRepository.java
b/components/camel-spring/src/main/java/org/apache/camel/spring/spi/ApplicationContextBeanRepository.java
index 3e0740b..4723ca5 100644
---
a/components/camel-spring/src/main/java/org/apache/camel/spring/spi/ApplicationContextBeanRepository.java
+++
b/components/camel-spring/src/main/java/org/apache/camel/spring/spi/ApplicationContextBeanRepository.java
@@ -41,18 +41,17 @@ public class ApplicationContextBeanRepository implements
BeanRepository {
public <T> T lookupByNameAndType(String name, Class<T> type) {
Object answer;
try {
- answer = applicationContext.getBean(name, type);
+ if (applicationContext.containsBean(name)) {
+ answer = applicationContext.getBean(name, type);
+ } else {
+ return null;
+ }
} catch (NoSuchBeanDefinitionException e) {
return null;
} catch (BeanNotOfRequiredTypeException e) {
return null;
}
- // just to be safe
- if (answer == null) {
- return null;
- }
-
try {
return type.cast(answer);
} catch (Throwable e) {
@@ -65,7 +64,11 @@ public class ApplicationContextBeanRepository implements
BeanRepository {
@Override
public Object lookupByName(String name) {
try {
- return applicationContext.getBean(name);
+ if (applicationContext.containsBean(name)) {
+ return applicationContext.getBean(name);
+ } else {
+ return null;
+ }
} catch (NoSuchBeanDefinitionException e) {
return null;
}