diff options
Diffstat (limited to 'spring-beans/src/main/java/org/springframework/beans/factory/UnsatisfiedDependencyException.java')
-rw-r--r-- | spring-beans/src/main/java/org/springframework/beans/factory/UnsatisfiedDependencyException.java | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/UnsatisfiedDependencyException.java b/spring-beans/src/main/java/org/springframework/beans/factory/UnsatisfiedDependencyException.java index 9ec35a7e..0403abfc 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/UnsatisfiedDependencyException.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/UnsatisfiedDependencyException.java @@ -31,6 +31,9 @@ import org.springframework.util.ClassUtils; @SuppressWarnings("serial") public class UnsatisfiedDependencyException extends BeanCreationException { + private InjectionPoint injectionPoint; + + /** * Create a new UnsatisfiedDependencyException. * @param resourceDescription description of the resource that the bean definition came from @@ -64,10 +67,42 @@ public class UnsatisfiedDependencyException extends BeanCreationException { * Create a new UnsatisfiedDependencyException. * @param resourceDescription description of the resource that the bean definition came from * @param beanName the name of the bean requested + * @param injectionPoint the injection point (field or method/constructor parameter) + * @param msg the detail message + * @since 4.3 + */ + public UnsatisfiedDependencyException( + String resourceDescription, String beanName, InjectionPoint injectionPoint, String msg) { + + super(resourceDescription, beanName, "Unsatisfied dependency expressed through " + injectionPoint + ": " + msg); + this.injectionPoint = injectionPoint; + } + + /** + * Create a new UnsatisfiedDependencyException. + * @param resourceDescription description of the resource that the bean definition came from + * @param beanName the name of the bean requested + * @param injectionPoint the injection point (field or method/constructor parameter) + * @param ex the bean creation exception that indicated the unsatisfied dependency + * @since 4.3 + */ + public UnsatisfiedDependencyException( + String resourceDescription, String beanName, InjectionPoint injectionPoint, BeansException ex) { + + this(resourceDescription, beanName, injectionPoint, (ex != null ? ex.getMessage() : "")); + initCause(ex); + } + + /** + * Create a new UnsatisfiedDependencyException. + * @param resourceDescription description of the resource that the bean definition came from + * @param beanName the name of the bean requested * @param ctorArgIndex the index of the constructor argument that couldn't be satisfied * @param ctorArgType the type of the constructor argument that couldn't be satisfied * @param msg the detail message + * @deprecated in favor of {@link #UnsatisfiedDependencyException(String, String, InjectionPoint, String)} */ + @Deprecated public UnsatisfiedDependencyException( String resourceDescription, String beanName, int ctorArgIndex, Class<?> ctorArgType, String msg) { @@ -84,7 +119,9 @@ public class UnsatisfiedDependencyException extends BeanCreationException { * @param ctorArgIndex the index of the constructor argument that couldn't be satisfied * @param ctorArgType the type of the constructor argument that couldn't be satisfied * @param ex the bean creation exception that indicated the unsatisfied dependency + * @deprecated in favor of {@link #UnsatisfiedDependencyException(String, String, InjectionPoint, BeansException)} */ + @Deprecated public UnsatisfiedDependencyException( String resourceDescription, String beanName, int ctorArgIndex, Class<?> ctorArgType, BeansException ex) { @@ -92,4 +129,13 @@ public class UnsatisfiedDependencyException extends BeanCreationException { initCause(ex); } + + /** + * Return the injection point (field or method/constructor parameter), if known. + * @since 4.3 + */ + public InjectionPoint getInjectionPoint() { + return this.injectionPoint; + } + } |