[{"id":"springbootintermediate-001","courseId":"spring-boot-intermediate","domain":"configuration-and-beans","topic":"Singleton and prototype bean scopes","prompt":"A prototype-scoped bean is requested from the container. Put these steps of its life, from creation to cleanup, in order.","hint":"Think about who owns the object once the container has handed it out.","explain":"A prototype bean is not tracked by the container after it is given out. Each phase belongs to either the container or the client, and the handover between them is the key point.","source":"https://docs.spring.io/spring-framework/reference/core/beans/factory-scopes.html","interaction":{"type":"sort","items":[{"text":"The container instantiates the bean","why":"Creation comes first; the container builds the object when it is requested."},{"text":"The container configures and assembles the bean","why":"Configuration happens right after creation, before the object is handed out."},{"text":"The container hands the bean to the client","why":"Once handed over, the container keeps no further record of that instance."},{"text":"The client cleans up and releases the resources","why":"Only the client can free the resources, because the container has let go."}]},"options":[],"answer":"o:abcd","explanation":"The container creates, configures and hands out a prototype bean, then stops tracking it; destruction callbacks are not called, so the client must clean up.","concept":"The container creates, configures and hands out a prototype bean, then stops tracking it; destruction callbacks are not called, so the client must clean up.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Prototype beans are created on each request, and the container never runs their destroy callbacks."]},{"id":"springbootintermediate-002","courseId":"spring-boot-intermediate","domain":"configuration-and-beans","topic":"@Primary bean selection","prompt":"A MovieRecommender has one single-valued MovieCatalog field, and two MovieCatalog beans are candidates. Which TWO statements about @Primary and @Fallback are true?","hint":"Look at what each annotation does when several beans compete for one dependency.","explain":"Several beans of one type can compete for a single injection point, so the container needs a tie-breaker. Spring provides annotations that mark a preferred bean and set aside the others.","source":"https://docs.spring.io/spring-framework/reference/core/beans/annotation-config/autowired-primary.html","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"@Primary makes a bean the preferred choice when several beans could fill a single-valued dependency.","why":"The page says @Primary gives a bean preference when multiple candidates exist for a single-valued dependency."},{"id":"b","text":"@Fallback, available from Spring Framework 6.2, marks beans other than the regular ones to be injected.","why":"The page says that as of 6.2, @Fallback demarcates beans other than the regular ones to be injected."},{"id":"c","text":"@Primary removes every other candidate bean from the context.","whyNot":"@Primary only gives one candidate preference; the other candidates remain available."},{"id":"d","text":"A List<MovieCatalog> injection point receives only the @Primary bean.","whyNot":"The page describes @Primary for single-valued dependencies, not for a list of candidates."},{"id":"e","text":"Two beans marked @Primary are both injected into one single-valued field.","whyNot":"A single-valued field receives one bean; @Primary decides only when exactly one primary bean exists."},{"id":"f","text":"@Fallback beans are injected in preference to the regular beans.","whyNot":"@Fallback marks the beans that are not regular; it does not put them ahead of the regular ones."}],"answer":"ab","explanation":"@Primary gives one candidate preference for a single-valued dependency; as of 6.2, @Fallback marks the non-regular beans, so a lone regular bean becomes effectively primary.","concept":"@Primary gives one candidate preference for a single-valued dependency; as of 6.2, @Fallback marks the non-regular beans, so a lone regular bean becomes effectively primary.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["@Primary breaks a tie only when exactly one candidate carries it."]},{"id":"springbootintermediate-003","courseId":"spring-boot-intermediate","domain":"configuration-and-beans","topic":"Lazy-initialized singleton beans","prompt":"A @Configuration class declares ReportCache as @Lazy. A non-lazy singleton, ReportService, takes a ReportCache through its constructor. When is the ReportCache created?","hint":"Consider which beans must exist before a non-lazy singleton can be created.","explain":"A @Lazy bean is not created when the context starts unless something needs it then. Spring also checks whether any eagerly created singleton depends on the bean, since that changes when it must exist.","source":"https://docs.spring.io/spring-framework/reference/core/beans/dependencies/factory-lazy-init.html","interaction":{"type":"single"},"options":[{"id":"a","text":"At application startup, because the non-lazy singleton depends on it.","why":"A lazy bean injected into a non-lazy singleton is still created at startup, to satisfy that singleton's dependencies."},{"id":"b","text":"On the first request for it from a client.","whyNot":"That is how a lazy bean behaves when nothing eager depends on it, but ReportService does depend on it."},{"id":"c","text":"Never, because @Lazy skips creating the bean.","whyNot":"@Lazy defers creation until the bean is first requested; it does not skip creation."},{"id":"d","text":"After startup, when ReportService first calls a method on it.","whyNot":"The container creates the dependency at startup so that ReportService can be satisfied, not at its first method call."}],"answer":"a","explanation":"A lazy bean is normally created on first request, but if a non-lazy singleton injects it, the container creates it at startup.","concept":"A lazy bean is normally created on first request, but if a non-lazy singleton injects it, the container creates it at startup.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["An eager dependency undoes @Lazy, so check who injects a lazy bean."]},{"id":"springbootintermediate-004","courseId":"spring-boot-intermediate","domain":"configuration-and-beans","topic":"@PostConstruct and @PreDestroy callbacks","prompt":"Once CommonAnnotationBeanPostProcessor is registered in the ApplicationContext, Spring calls a @PostConstruct method at the same lifecycle point as the corresponding Spring lifecycle interface method.","hint":"Think about what the post-processor enables for annotated methods.","explain":"Spring can call setup and teardown methods on a bean without the bean implementing a Spring interface. Java's standard lifecycle annotations mark such methods, and a registered post-processor recognizes them.","source":"https://docs.spring.io/spring-framework/reference/core/beans/annotation-config/postconstruct-and-predestroy-annotations.html","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","why":"The page says that, provided the post-processor is registered, the annotated method runs at the same point as the corresponding lifecycle method."},{"id":"b","text":"False","whyNot":"The page states the annotated method is invoked at that same lifecycle point, so the statement is not false."}],"answer":"a","explanation":"With CommonAnnotationBeanPostProcessor registered, @PostConstruct and @PreDestroy methods run at the same lifecycle points as the matching Spring callback methods.","concept":"With CommonAnnotationBeanPostProcessor registered, @PostConstruct and @PreDestroy methods run at the same lifecycle points as the matching Spring callback methods.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["@PostConstruct and @PreDestroy are JSR-250 annotations that Spring honours through the post-processor."]},{"id":"springbootintermediate-005","courseId":"spring-boot-intermediate","domain":"configuration-and-beans","topic":"Generic types as autowiring qualifiers","prompt":"A configuration defines stringStore, a Store<String>, and integerStore, a Store<Integer>. A bean declares @Autowired private List<Store<Integer>> stores; What does the list contain?","hint":"Generic type arguments can act as implicit qualifiers.","explain":"Spring can tell apart beans that share one generic interface by their type arguments, such as the String and Integer variants. The same matching applies beyond a single injection point.","source":"https://docs.spring.io/spring-framework/reference/core/beans/annotation-config/generics-as-qualifiers.html","interaction":{"type":"single"},"options":[{"id":"a","text":"Only integerStore, because the <Integer> generic filters out the String store.","why":"Generic arguments also qualify beans collected into a List, so only the Store<Integer> bean is included."},{"id":"b","text":"Both stores, because a List ignores generic arguments.","whyNot":"Generic arguments act as qualifiers for lists too, so the Store<String> bean is excluded."},{"id":"c","text":"Nothing, because Spring cannot inject a generic type into a List.","whyNot":"The page shows a List of a generic type being autowired, with only the matching beans included."},{"id":"d","text":"Only stringStore, because the first Store bean declared wins.","whyNot":"The generic argument decides which beans qualify, not the order in which they are declared."}],"answer":"a","explanation":"Generic type arguments act as implicit qualifiers, and they also filter the beans collected into a List, Map or array injection point.","concept":"Generic type arguments act as implicit qualifiers, and they also filter the beans collected into a List, Map or array injection point.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Store<Integer> and Store<String> beans can be autowired apart without @Qualifier, because the generic qualifies them."]}]