Scrivio Interview library

IoC container

27 questions in 8 subtopics.

Inversion of control

ConceptFoundations6 min read
What does inversion of control mean in Spring, and how is it different from a class creating its own dependencies or using a service locator?
DesignIntermediate6 min read
A colleague argues that Spring's IoC container adds hidden magic and that plain constructors with a hand-written main wiring class would be clearer for a small service. When do you agree?
LeadershipPrincipal6 min read
Why did dependency injection containers become standard in enterprise Java, and how have newer approaches such as build-time DI and AOT changed the trade-offs?

BeanFactory vs ApplicationContext

ConceptFoundations5 min read
What does ApplicationContext add on top of BeanFactory?
InternalsIntermediate6 min read
What happens during ApplicationContext.refresh()? Name the main steps in order.
ScenarioAdvanced6 min read
A large Spring Boot service takes 45 seconds to start, mostly before the web server is listening. How would you analyse and reduce startup time across your service fleet?

Bean definitions

ConceptFoundations5 min read
What is a BeanDefinition in Spring, and what information does it hold?
CodingIntermediate6 min read
Show two ways to register beans programmatically in Spring, for example registering one client bean per entry in a configuration list.
DesignAdvanced6 min read
You are building an internal library that must create one HTTP client bean per downstream service listed in configuration. Compare doing this with registered bean definitions versus a single factory bean holding a map.

Component scanning

ConceptFoundations5 min read
What do @Component, @Service, @Repository and @Controller have in common, and what does @Repository add?
DebuggingFoundations6 min read
A @Service class in package com.acme.billing is not found at startup, and the application class is in com.acme.app. Why, and what are the fixes?
ScenarioIntermediate6 min read
A shared library uses @ComponentScan to register its beans, and consuming applications get duplicate or unwanted beans. How should the library expose beans instead?
LeadershipPrincipal7 min read
Spring's classpath scanning made it easy to add beans, but in large codebases it also makes it hard to know what is in the context. What container standards would you set for a large organisation's Spring services over the next decade?

@Configuration and @Bean

CodingFoundations6 min read
What does this print, and why?
@Configuration
class AppConfig {
@Bean
Repo repo() {
return new Repo();
}
@Bean
ServiceA a() {
return new ServiceA(repo());
}
@Bean
ServiceB b() {
return new ServiceB(repo());
}
}
where Repo prints a line in its constructor.
DebuggingFoundations6 min read
A @Bean method that returns a PropertySourcesPlaceholderConfigurer causes a warning and @Value fields in the same configuration class are null. Why, and what is the fix?
ConceptIntermediate5 min read
When should you declare beans with @Bean methods instead of annotating the class with @Component?
LeadershipPrincipal7 min read
Spring configuration moved from XML to annotations and Java configuration, and now to AOT-generated code. Your company still has large XML configurations in older services. What is your long-term plan for them?

ProxyBeanMethods and lite mode

ConceptFoundations5 min read
What is the difference between full @Configuration mode and lite mode, and what does proxyBeanMethods = false change?
DebuggingIntermediate6 min read
After changing a configuration class to @Configuration(proxyBeanMethods = false), the application has two DataSource connection pools. Explain the code that caused it and the fix.
LeadershipAdvanced6 min read
Would you set a standard that all configuration classes in your organisation use proxyBeanMethods = false? What are the arguments?

Context hierarchy

ConceptFoundations6 min read
What is a parent-child ApplicationContext hierarchy, and where did classic Spring MVC applications use one?
DebuggingIntermediate6 min read
In a classic Spring MVC application with root and servlet contexts, @Transactional on a service does not work. The service is scanned in the servlet context. Why?
DesignAdvanced6 min read
When might you deliberately use context hierarchies in a Spring Boot application today, for example with SpringApplicationBuilder.parent and child?
ScenarioPrincipal7 min read
A product built on Spring a decade ago loads customer plugins into child application contexts with separate class loaders. The team wants to move to Spring Boot 4. What risks do you assess and what would you redesign?

FactoryBean and factory methods

ConceptFoundations5 min read
What is a Spring FactoryBean, how is it different from a @Bean factory method, and what does the & prefix in getBean("&myFactory") return?
DebuggingIntermediate7 min read
A custom FactoryBean returns null from getObjectType(), and autowiring by type of its product fails or creates the bean too early during startup. Explain why, and how static and instance factory methods in bean definitions compare.
DesignAdvanced6 min read
You maintain an internal starter that creates a client per configured service using FactoryBean classes written ten years ago. With AOT and native images in scope, would you keep FactoryBeans, switch to @Bean methods, or use bean registration APIs? Explain.