nerdexam
Broadcom-VMware

2V0-72.22PSE · Question #64

Which functions are possible only when using interfaces as spring beans?

The correct answer is B. JDK Dynamic Proxying. JDK Dynamic Proxying is the only option that requires a Spring bean to implement an interface. The java.lang.reflect.Proxy mechanism (used by Spring AOP under the hood) can only create a proxy by implementing an existing interface - it has no way to subclass a concrete class…

Core Spring

Question

Which functions are possible only when using interfaces as spring beans?

Options

  • AException Handling
  • BJDK Dynamic Proxying
  • CTest Application Context
  • DDependency Injection

How the community answered

(16 responses)
  • A
    13% (2)
  • B
    81% (13)
  • C
    6% (1)

Explanation

JDK Dynamic Proxying is the only option that requires a Spring bean to implement an interface. The java.lang.reflect.Proxy mechanism (used by Spring AOP under the hood) can only create a proxy by implementing an existing interface - it has no way to subclass a concrete class. When you use CGLIB instead, Spring can proxy concrete classes, but JDK Dynamic Proxying is strictly interface-dependent.

Why the others are wrong:

  • A (Exception Handling): @ExceptionHandler and @ControllerAdvice operate on concrete classes and methods - no interface needed.
  • C (Test Application Context): @SpringBootTest and ApplicationContext loading work identically whether beans are concrete classes or interface-backed - the container doesn't care.
  • D (Dependency Injection): DI works fine with concrete classes; Spring resolves beans by type or name regardless of whether an interface is involved.

Memory tip: Think "JDK proxy = Java interface contract" - the java.lang.reflect.Proxy class is in the JDK itself and has always required an interface since Java 1.1. If the Spring bean has no interface, Spring must fall back to CGLIB. JDK Dynamic = interface only; CGLIB = works anywhere.

Topics

#JDK Dynamic Proxying#Spring Beans#AOP#Proxy Mechanisms

Community Discussion

No community discussion yet for this question.

Full 2V0-72.22PSE Practice