What is the recommended way to find out the actual runtime type of a bean in Spring?
The recommended way is to use BeanFactory.getType for the specified bean name.
How can you configure a bean definition for a nested class?
You can use either the binary name or the source name of the nested class, separated by a dollar sign ($) or a dot (.). For example, com.example.SomeThing$OtherThing or com.example.SomeThing.OtherThing.
1/119
p.17
Dependency Injection (DI) Techniques

What is the recommended way to find out the actual runtime type of a bean in Spring?

The recommended way is to use BeanFactory.getType for the specified bean name.

p.13
XML and Java-based Configuration

How can you configure a bean definition for a nested class?

You can use either the binary name or the source name of the nested class, separated by a dollar sign ($) or a dot (.). For example, com.example.SomeThing$OtherThing or com.example.SomeThing.OtherThing.

p.14
Bean Lifecycle and Management

In the provided example, how is the ClientService instance created?

The ClientService instance is created using the createInstance method, which returns a static instance of ClientService.

p.18
Dependency Injection (DI) Techniques

What does the SimpleMovieLister class demonstrate about dependencies?

It shows that a POJO can have dependencies without relying on container-specific interfaces or annotations.

p.18
Constructor-based vs Setter-based Dependency Injection

What is the significance of the ThingOne class in the context of constructor argument resolution?

ThingOne demonstrates how multiple constructor arguments can be injected, highlighting the importance of type matching in dependency resolution.

p.4
Spring Framework Integration with AspectJ

How can Spring’s integration with AspectJ be utilized?

It can be used to configure objects that have been created outside the control of an IoC container.

p.21
Constructor-based vs Setter-based Dependency Injection

What JDK annotation can be used to explicitly name constructor arguments without compiling with the debug flag?

@ConstructorProperties

p.18
Constructor-based vs Setter-based Dependency Injection

How does constructor argument resolution work in Spring?

Constructor argument resolution matches by using the argument's type, and the order of arguments in the bean definition determines the order they are supplied during instantiation.

p.23
Dependency Injection (DI) Techniques

Why does the Spring team advocate for constructor injection?

Constructor injection allows for the implementation of application components as immutable objects and ensures that required dependencies are not null, returning fully initialized components to the client code.

p.4
Configuration Metadata in Spring

What does the 'id' attribute in an XML bean definition represent?

The 'id' attribute is a string that identifies the individual bean definition.

p.23
Dependency Injection (DI) Techniques

What happens during the bean dependency resolution process in Spring?

The ApplicationContext is initialized with configuration metadata, dependencies are expressed as properties or constructor arguments, and the Spring container validates the configuration as beans are created.

p.6
XML and Java-based Configuration

What is the purpose of the <import/> element in Spring XML configuration?

The <import/> element is used to load bean definitions from another file or files.

p.22
Dependency Injection (DI) Techniques

How is a MovieFinder property defined in Kotlin for dependency injection?

In Kotlin, the MovieFinder property is defined as a late-initialized property using 'lateinit var movieFinder: MovieFinder'.

p.12
Bean Lifecycle and Management

What is a bean definition in Spring?

A bean definition is essentially a recipe for creating one or more objects, containing configuration metadata that the container uses to instantiate the bean.

p.11
Bean Naming and Aliasing

What is the convention for naming beans in Spring?

Beans should start with a lowercase letter and follow camel-case notation, such as accountManager or userDao.

p.3
Configuration Metadata in Spring

How are beans typically defined in Java configuration?

Beans are typically defined using @Bean-annotated methods within a @Configuration class.

p.8
ApplicationContext and BeanFactory

How can you retrieve a bean instance from the ApplicationContext?

You can retrieve a bean instance using the method getBean(String name, Class<T> requiredType).

p.19
Dependency Injection (DI) Techniques

What is the purpose of the <constructor-arg/> element in Spring configuration?

It specifies the constructor arguments for a bean, allowing Spring to inject dependencies.

p.19
Dependency Injection (DI) Techniques

What happens when a simple type, like <value>true</value>, is used in Spring configuration?

Spring cannot determine the type of the value and cannot match by type without additional help.

p.17
Dependency Injection (DI) Techniques

What are the two major variants of Dependency Injection?

The two major variants are Constructor-based dependency injection and Setter-based dependency injection.

p.23
Dependency Injection (DI) Techniques

When should setter injection be used?

Setter injection should primarily be used for optional dependencies that can have reasonable default values. It allows for reconfiguration or re-injection of dependencies later.

p.5
XML and Java-based Configuration

What is the XML configuration file for service layer objects called?

services.xml

p.15
Dependency Injection (DI) Techniques

How is the 'clientService' bean created in the example?

The 'clientService' bean is created using the 'serviceLocator' factory bean and the 'createClientServiceInstance' factory method.

p.22
Configuration Metadata in Spring

What is a BeanDefinition in the context of Spring?

A BeanDefinition is used to configure the dependencies of beans in the Spring container.

p.11
Bean Naming and Aliasing

What is the purpose of the <alias/> element in XML-based configuration metadata?

The <alias/> element allows you to introduce an alias for a bean that is defined elsewhere, useful in large systems with split configurations.

p.9
Dependency Injection (DI) Techniques

What should your application code ideally avoid in relation to Spring APIs?

Your application code should ideally avoid calls to the getBean() method and thus have no dependency on Spring APIs at all.

p.21
Setter-based Dependency Injection

How is Setter-based Dependency Injection accomplished?

By the container calling setter methods on your beans after invoking a no-argument constructor or a no-argument static factory method.

p.23
Dependency Injection (DI) Techniques

What is the recommended use of constructor-based and setter-based Dependency Injection (DI)?

Use constructors for mandatory dependencies and setter methods for optional dependencies. Constructor injection is preferred for required dependencies to ensure immutability and that dependencies are not null.

p.13
Dependency Injection (DI) Techniques

What is required when creating a bean by the constructor approach?

The class does not need to implement specific interfaces or be coded in a specific fashion; simply specifying the bean class should suffice. However, a default (empty) constructor may be needed depending on the IoC used.

p.7
Configuration Metadata in Spring

Why is it not recommended to use relative paths like '../' in classpath URLs?

Using relative paths creates a dependency on files outside the current application, which can lead to incorrect directory choices during runtime resolution.

p.7
Configuration Metadata in Spring

What feature does the Spring namespace provide for configuration?

The namespace provides the import directive feature, allowing for further configuration beyond plain bean definitions.

p.2
ApplicationContext and BeanFactory

What does the ApplicationContext interface represent?

The ApplicationContext interface represents the Spring IoC container and is responsible for instantiating, configuring, and assembling the beans.

p.10
Dependency Injection (DI) Techniques

What are references to other beans called?

They are called collaborators or dependencies.

p.12
Bean Naming and Aliasing

What is the purpose of the <alias> tag in Spring configuration?

The <alias> tag allows a bean to be referred to by multiple names, creating a unique namespace for each reference while pointing to the same object.

p.2
ApplicationContext and BeanFactory

What is typically required in a web application to instantiate a Spring IoC container?

A simple eight (or so) lines of boilerplate web descriptor XML in the web.xml file of the application typically suffices.

p.16
Bean Lifecycle and Management

What is the difference between 'factory bean' and 'FactoryBean' in Spring?

'Factory bean' refers to a general concept of a bean that creates objects, while 'FactoryBean' (capitalized) refers to a specific implementation class in Spring.

p.3
Configuration Metadata in Spring

How are beans defined in XML-based configuration metadata?

Beans are defined as <bean/> elements inside a top-level <beans/> element.

p.5
XML and Java-based Configuration

What is the purpose of the xsi:schemaLocation attribute in the XML configuration?

It defines the location of the XML schema for validation.

p.9
Bean Lifecycle and Management

What does the Spring IoC container manage?

The Spring IoC container manages one or more beans, which are created based on the configuration metadata supplied to the container.

p.4
Dependency Injection (DI) Techniques

What is the responsibility of DAOs and business logic in relation to domain objects?

DAOs and business logic are usually responsible for creating and loading domain objects.

p.10
Configuration Metadata in Spring

What are bean behavioral configuration elements?

They state how the bean should behave in the container, including scope and lifecycle callbacks.

p.6
XML and Java-based Configuration

How can bean definitions span multiple XML files in Spring?

Bean definitions can span multiple XML files by using the application context constructor to load bean definitions from multiple Resource locations or by using the <import/> element to load definitions from other files.

p.4
ApplicationContext and BeanFactory

What are the resource strings supplied to an ApplicationContext constructor used for?

They let the container load configuration metadata from various external resources, such as the local file system and the Java CLASSPATH.

p.6
XML and Java-based Configuration

What must be valid XML bean definitions according to the Spring Schema?

The contents of the files being imported, including the top level <beans/> element, must be valid XML bean definitions.

p.6
Dependency Injection (DI) Techniques

What is the significance of the id and ref elements in Spring configuration?

The id and ref elements express the dependency between collaborating objects.

p.12
Bean Lifecycle and Management

What are the two ways to use the Class property in bean definitions?

The Class property can be used to specify the bean class for direct construction or to specify the class containing a static factory method for bean creation.

p.11
Bean Naming and Aliasing

What was the change in the definition of the id attribute in Spring 3.1?

In Spring 3.1, the id attribute was changed from an xsd:ID type to an xsd:string type, allowing more characters.

p.1
Bean Lifecycle and Management

What are the two main packages that form the basis for Spring Framework’s IoC container?

The two main packages are org.springframework.beans and org.springframework.context.

p.21
Setter-based Dependency Injection

What is a characteristic of a class that uses pure setter injection?

It is a POJO that has no dependencies on container specific interfaces, base classes, or annotations.

p.20
XML and Java-based Configuration

What must be enabled in your code for Spring to look up the parameter name from the constructor?

Your code must be compiled with the debug flag enabled.

p.7
Configuration Metadata in Spring

How does the Groovy Bean Definition DSL compare to XML bean definitions?

The Groovy Bean Definition DSL is largely equivalent to XML bean definitions and supports Spring’s XML configuration namespaces.

p.14
Bean Lifecycle and Management

What should be specified in the factory-bean attribute when using an instance factory method?

The factory-bean attribute should specify the name of a bean that contains the instance method to be invoked.

p.16
Dependency Injection (DI) Techniques

What is the purpose of the DefaultServiceLocator class in the provided example?

The DefaultServiceLocator class is used to create instances of ClientService and AccountService, demonstrating how a factory bean can be managed and configured through dependency injection.

p.10
Bean Lifecycle and Management

Why is it important to register bean metadata early?

To ensure the container can properly reason about them during autowiring and other introspection steps.

p.11
Bean Naming and Aliasing

How does Spring handle bean names for unnamed components during component scanning?

Spring generates bean names by taking the simple class name and converting its initial character to lowercase.

p.9
XML and Java-based Configuration

How can you load bean definitions from XML files in Java?

You can load bean definitions from XML files in Java using the XmlBeanDefinitionReader, as shown in the example: new XmlBeanDefinitionReader(context).loadBeanDefinitions('services.xml', 'daos.xml');

p.8
ApplicationContext and BeanFactory

What is the Groovy equivalent for creating an ApplicationContext?

ApplicationContext context = new GenericGroovyApplicationContext("services.groovy", "daos.groovy");

p.20
XML and Java-based Configuration

What does the index attribute in constructor arguments start from?

The index is 0-based.

p.17
Dependency Injection (DI) Techniques

How does Dependency Injection improve code quality?

DI makes code cleaner and enhances decoupling, allowing classes to be easier to test, especially when dependencies are on interfaces or abstract base classes.

p.23
Dependency Injection (DI) Techniques

What is a potential drawback of having a large number of constructor arguments?

A large number of constructor arguments is considered a bad code smell, indicating that the class may have too many responsibilities and should be refactored for better separation of concerns.

p.4
Configuration Metadata in Spring

What does the 'class' attribute in an XML bean definition specify?

The 'class' attribute defines the type of the bean and uses the fully qualified classname.

p.12
Bean Naming and Aliasing

How can you create aliases for beans in Java configuration?

In Java configuration, you can use the @Bean annotation to provide aliases for beans.

p.10
Bean Naming and Aliasing

What must every bean identifier be within the container?

Unique.

p.11
Bean Naming and Aliasing

What happens if you do not supply a name or id for a bean?

If no name or id is supplied, the container generates a unique name for that bean.

p.1
Dependency Injection (DI) Techniques

What does IoC stand for and how is it related to Dependency Injection (DI)?

IoC stands for Inversion of Control, which is a principle that is also known as Dependency Injection (DI). It involves the container injecting dependencies into objects rather than the objects controlling their own instantiation.

p.19
Dependency Injection (DI) Techniques

In the provided Kotlin example, why is there no ambiguity when injecting ThingTwo and ThingThree into ThingOne?

Because ThingTwo and ThingThree are not related by inheritance, allowing Spring to resolve the dependencies without needing explicit indexes or types.

p.2
Bean Lifecycle and Management

What is a bean in the context of Spring IoC container?

A bean is an object that is instantiated, assembled, and managed by a Spring IoC container.

p.17
Constructor-based vs Setter-based Dependency Injection

How is Constructor-based Dependency Injection accomplished?

Constructor-based DI is accomplished by the container invoking a constructor with arguments that represent dependencies.

p.3
Configuration Metadata in Spring

What is configuration metadata in the Spring IoC container?

Configuration metadata represents how application developers instruct the Spring container to instantiate, configure, and assemble objects in their application.

p.2
ApplicationContext and BeanFactory

What is a common way to create an instance of ApplicationContext in standalone applications?

It is common to create an instance of ClassPathXmlApplicationContext or FileSystemXmlApplicationContext.

p.5
XML and Java-based Configuration

What is the XML configuration file for data access objects called?

daos.xml

p.12
XML and Java-based Configuration

What attribute is typically mandatory in XML-based bean configuration?

The class attribute in the <bean/> element is usually mandatory, specifying the type of object to be instantiated.

p.22
XML and Java-based Configuration

What are the common ways Spring users configure beans?

Spring users typically configure beans using XML bean definitions, annotated components, or @Bean methods in Java-based @Configuration classes.

p.9
XML and Java-based Configuration

What is the role of GroovyBeanDefinitionReader?

The GroovyBeanDefinitionReader is used to load bean definitions from Groovy files, similar to how XmlBeanDefinitionReader works for XML files.

p.1
ApplicationContext and BeanFactory

What additional functionalities does ApplicationContext provide over BeanFactory?

ApplicationContext provides easier integration with AOP features, message resource handling for internationalization, event publication, and application-layer specific contexts.

p.18
Dependency Injection (DI) Techniques

What is the purpose of the constructor in the SimpleMovieLister class?

The constructor allows the Spring container to inject a MovieFinder dependency.

p.17
Dependency Injection (DI) Techniques

What is Dependency Injection (DI)?

Dependency Injection is a process where objects define their dependencies through constructor arguments, factory method arguments, or properties set after construction, and the container injects those dependencies when creating the bean.

p.19
Bean Lifecycle and Management

What are the two private final fields in the ExampleBean class?

The two fields are 'years' (an int) and 'ultimateAnswer' (a String).

p.2
Configuration Metadata in Spring

How does the Spring IoC container get its instructions?

The container gets its instructions on what objects to instantiate, configure, and assemble by reading configuration metadata.

p.23
Dependency Injection (DI) Techniques

How does Spring handle type conversion for bean properties?

Spring can convert values supplied in string format to built-in types like int, long, String, and boolean during the bean creation process.

p.15
Dependency Injection (DI) Techniques

What is the purpose of the factory bean in the provided example?

The factory bean is used to create instances of other beans, such as 'clientService' and 'accountService', through specified factory methods.

p.11
Bean Naming and Aliasing

What attributes are used to specify bean identifiers in XML-based configuration metadata?

The id attribute and the name attribute are used to specify bean identifiers.

p.15
Dependency Injection (DI) Techniques

Can a factory class hold multiple factory methods?

Yes, a factory class can hold more than one factory method, as shown with 'createClientServiceInstance' and 'createAccountServiceInstance' in the example.

p.5
Bean Lifecycle and Management

What type of DAO is defined by the 'accountDao' bean in daos.xml?

org.springframework.samples.jpetstore.dao.jpa.JpaAccountDao

p.1
Inversion of Control (IoC) Container

What is the primary function of the Spring Framework’s Inversion of Control (IoC) container?

The IoC container manages the instantiation and injection of dependencies for beans, allowing objects to define their dependencies through constructor arguments, factory method arguments, or properties.

p.20
XML and Java-based Configuration

How can you specify the index of constructor arguments in a Spring bean configuration?

You can use the 'index' attribute to explicitly specify the index of constructor arguments.

p.20
XML and Java-based Configuration

How can you resolve ambiguity in constructor arguments of the same type?

You can specify the constructor parameter name using the 'name' attribute for value disambiguation.

p.7
Configuration Metadata in Spring

What is the Groovy Bean Definition DSL used for in Spring?

It is used for externalized configuration metadata, allowing bean definitions to be expressed in a Groovy file format.

p.6
Configuration Metadata in Spring

What does the property name element refer to in Spring configuration?

The property name element refers to the name of the JavaBean property.

p.9
Configuration Metadata in Spring

What are BeanDefinition objects?

BeanDefinition objects represent bean definitions within the container and contain metadata such as the package-qualified class name of the bean.

p.20
XML and Java-based Configuration

What is the purpose of the 'type' attribute in a Spring bean configuration?

The 'type' attribute allows the container to use type matching with simple types for constructor arguments.

p.7
Configuration Metadata in Spring

What is a better alternative to using relative paths for resource locations?

Using fully qualified resource locations, such as 'file:C:/config/services.xml' or 'classpath:/config/services.xml', is preferable.

p.14
Bean Lifecycle and Management

What is the purpose of the factory-method attribute in a bean definition?

The factory-method attribute specifies the name of the method that will be invoked to create the bean instance.

p.13
Bean Lifecycle and Management

Can Spring manage non-JavaBeans?

Yes, Spring can manage non-bean-style classes, including legacy connection pools that do not adhere to the JavaBean specification.

p.10
Configuration Metadata in Spring

What does the bean definition metadata translate to?

It translates to a set of properties that make up each bean definition.

p.3
Configuration Metadata in Spring

What is the traditional format for supplying configuration metadata in Spring?

Configuration metadata is traditionally supplied in a simple and intuitive XML format.

p.8
ApplicationContext and BeanFactory

What is the most flexible variant of ApplicationContext?

The most flexible variant is GenericApplicationContext in combination with reader delegates.

p.14
Bean Lifecycle and Management

How does instantiation using an instance factory method differ from static factory method instantiation?

Instantiation using an instance factory method invokes a non-static method of an existing bean, while static factory method instantiation calls a static method.

p.2
Configuration Metadata in Spring

What formats can configuration metadata be represented in?

Configuration metadata can be represented in XML, Java annotations, or Java code.

p.22
Dependency Injection (DI) Techniques

What is the purpose of the setter method in the SimpleMovieLister class?

The setter method allows the Spring container to inject a MovieFinder dependency into the SimpleMovieLister.

p.10
ApplicationContext and BeanFactory

What methods does DefaultListableBeanFactory support for registration?

It supports registerSingleton(..) and registerBeanDefinition(..) methods.

p.5
Bean Lifecycle and Management

In the services.xml file, what is the class of the bean with id 'petStore'?

org.springframework.samples.jpetstore.services.PetStoreServiceImpl

p.15
Dependency Injection (DI) Techniques

What is the role of the 'DefaultServiceLocator' class?

The 'DefaultServiceLocator' class contains methods to create instances of services, such as 'ClientService', and holds the service instances.

p.8
ApplicationContext and BeanFactory

What is the purpose of the ApplicationContext in Spring?

The ApplicationContext is an advanced factory interface that maintains a registry of different beans and their dependencies.

p.1
ApplicationContext and BeanFactory

What is the difference between BeanFactory and ApplicationContext in Spring?

BeanFactory provides basic functionality and configuration framework, while ApplicationContext is a superset of BeanFactory that adds enterprise-specific features such as AOP integration, message resource handling, and event publication.

p.13
XML and Java-based Configuration

How do you specify a bean class in XML-based configuration?

You can specify your bean class using the <bean> tag, for example: <bean id="exampleBean" class="examples.ExampleBean"/>.

p.13
Configuration Metadata in Spring

How do you define a bean that is created with a static factory method?

Use the class attribute to specify the class containing the static factory method and an attribute named factory-method to specify the name of the factory method.

p.3
Configuration Metadata in Spring

What alternative forms of configuration metadata are supported by the Spring IoC container?

The Spring IoC container supports annotation-based configuration and Java-based configuration.

p.3
Configuration Metadata in Spring

What annotations are used in Java-based configuration in Spring?

The annotations used include @Configuration, @Bean, @Import, and @DependsOn.

p.5
Dependency Injection (DI) Techniques

Which property is referenced by the 'petStore' bean in services.xml?

accountDao and itemDao

p.9
ApplicationContext and BeanFactory

What is the purpose of the GenericApplicationContext in Spring?

The GenericApplicationContext is used to create an application context that can load bean definitions from various sources, such as XML or Groovy files.

p.8
ApplicationContext and BeanFactory

How do you retrieve a configured instance of PetStoreService in Kotlin?

val service = context.getBean<PetStoreService>("petStore")

p.5
ApplicationContext and BeanFactory

What is the purpose of Spring's Resource abstraction?

It provides a convenient mechanism for reading an InputStream from locations defined in a URI syntax.

p.10
ApplicationContext and BeanFactory

What is the purpose of the ApplicationContext's getBeanFactory() method?

It returns the DefaultListableBeanFactory implementation, allowing registration of existing objects created outside the container.

p.16
Bean Lifecycle and Management

What does the term 'factory bean' refer to in Spring documentation?

In Spring documentation, 'factory bean' refers to a bean that is configured in the Spring container and creates objects through an instance or static factory method.

p.22
Dependency Injection (DI) Techniques

What types of Dependency Injection does the ApplicationContext support?

The ApplicationContext supports both constructor-based and setter-based Dependency Injection.

p.16
Bean Lifecycle and Management

Why is determining a bean's runtime type considered non-trivial?

Determining a bean's runtime type is non-trivial because the specified class in the bean metadata may not reflect the actual runtime type, especially if a factory method or a FactoryBean class is involved.

p.3
Configuration Metadata in Spring

What types of objects are typically defined as beans in Spring?

Typically, service layer objects, data access objects (DAOs), presentation objects, and infrastructure objects are defined as beans.

p.8
ApplicationContext and BeanFactory

What is the Java code to create and configure beans using ApplicationContext?

ApplicationContext context = new ClassPathXmlApplicationContext("services.xml", "daos.xml");

Study Smarter, Not Harder
Study Smarter, Not Harder