Load when reading a Java stack trace to identify root cause, diagnosing a NullPointerException, LazyInitializationException, BeanCreationException, or ContextRefreshException in Spring Boot, using Spring Boot Actuator endpoints (/actuator/env, /actuator/beans, /actuator/conditions, /actuator/loggers) to diagnose a runtime issue, configuring JDWP remote debug for a JVM in Docker, reading a thread dump to find deadlocks or blocked threads, or when asked "how do I debug this", "what does this stack trace mean", "why is the application context not starting", "how do I attach a debugger to this Docker container".
Find the root cause, not the top frame. The top frame is often a framework wrapper.
org.springframework.web.util.NestedServletException: Handler dispatch failed
at org.springframework.web.servlet.DispatcherServlet.noHandlerFound(...) ← framework noise
...
Caused by: org.hibernate.LazyInitializationException: could not initialize proxy ← THIS
at org.hibernate.proxy.AbstractLazyInitializer.initialize(...)
at com.example.orders.service.OrderService.getOrderDetails(OrderService.java:47) ← YOUR CODE
Rule: Scroll down to the last Caused by: — that is the actual failure.
LazyInitializationExceptionorg.hibernate.LazyInitializationException: failed to lazily initialize a collection
of role: com.example.Order.items, could not initialize proxy - no Session
Root cause: Accessing a lazy collection outside of a transaction — the Hibernate session is closed.
Where to look: The line in YOUR code that accesses order.getItems(). Is it inside a @Transactional method? Or are you accessing it after the transaction has already committed (e.g., in a controller or DTO mapper)?
Fixes:
@Transactional service methodSELECT o FROM Order o JOIN FETCH o.items WHERE o.id = :idBeanCreationExceptionorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'orderService'
...
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException
...
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.example.PaymentClient'
Root cause: A dependency can't be found. Follow the Caused by chain to the missing bean.
Checklist:
@Service, @Component, @Repository?@SpringBootApplication? (Must be in a subpackage of the main class)@Profile condition preventing it from loading in this environment?@ConditionalOn* that evaluates to false?Diagnose with Actuator:
curl http://localhost:8080/actuator/conditions | jq '.positiveMatches | keys' # what loaded
curl http://localhost:8080/actuator/conditions | jq '.negativeMatches | keys' # what didn't load
ContextRefreshException / Application fails to startApplication failed to start
...
Caused by: java.lang.IllegalStateException: Failed to load ApplicationContext
Checklist (in order):
application.yml syntax — YAML is whitespace-sensitive@Value("${some.property}") — is it set in config?The dependencies of some of the beans in the application context form a cycleFind missing properties:
grep -r "@Value" src/main/java --include="*.java" | grep -v "test"
# Cross-reference with application.yml
NullPointerException in Spring Codejava.lang.NullPointerException: Cannot invoke "com.example.Order.getId()" because "order" is null
at com.example.OrderService.processOrder(OrderService.java:83)
Java 17+ NPEs include the null reference in the message. Read it literally: order is null at line 83.
Common Spring causes:
Optional but code calls .get() without checking@Autowired field is null — the class was instantiated via new instead of Spring (not a bean)@MockBean not set up in a test — returns null by defaultEnable for debugging (dev/staging only — never expose in prod without auth):
# application-local.yml