wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Spring Final Exam Worksheet Extraction

Total questions: 60

Worksheet time: 30mins

Name
Class
Date
1.

In a Spring XML configuration file, how would you define a bean definition for the class EmployeeServiceImpl where it has multiple aliases (i.e., names)?

a)

  <bean class=”EmployeeServiceImpl”/>

b)

  <bean id=”myID” name=”another, andAnother” class=”EmployeeServiceImpl”/>

c)

<bean id=”myID” class=”EmployeeServiceImpl”/>

d)

   <bean id=”myID another, andAnother” class=”EmployeeServiceImpl”/>

2.

You have an EmployeeService bean that has a three-argument constructor: public EmployeeService(String s, Integer i, Boolean b). Using XML, how would you configure this bean?

a)

All the above

b)

  <bean id="emplService class="EmployeeServiceImpl"  >

<constructor-arg index="2" value="true"/>

<constructor-arg index="0" value="hello"/>

<constructor-arg value=“3" />

</bean>

c)

<bean id="emplService class="EmployeeServiceImpl"  >

<constructor-arg name="b' value="true"/>

<constructor-arg value="hello"/>

<constructor-arg type="int" value=“3" />

</bean>

d)

  <bean id="emplService class="EmployeeServiceImpl"  >

<constructor-arg name="b' value="true"/>

<constructor-arg index="0" value="hello"/>

<constructor-arg value=“3" />

</bean>

3.

What are key advantages of using the Spring framework?

a)

All of the above

b)

Promotes decoupling and reusability

c)

Code is coupled to Spring

d)

Object dependencies are clearly defined in the application code itself

4.

What are we defining here? A principle where the control of a program, i.e., delegations from one object to another, are inverted: instead of the programmer controlling the flow in code, external sources (framework, services, configuration resources) take control of it.

a)

Inversion of control

b)

Inheritance

c)

Code to the interface

d)

Dependency injection

5.

What are we defining here? A design pattern where class X is dependent on Y. So rather than creating an object of Y within class X, we can inject the dependencies via a constructor or setter injection.

a)

Dependency injection

b)

Inheritance

c)

Inversion of control

d)

Code to the interface

6.

What types of dependency injection are there in XML configurations?

a)

Constructor

b)

Method injection

c)

Setter

d)

Field

7.

ApplicationContext implementations have what type of built-in class type to read metadata?

a)

JSON Parser

b)

Resource

c)

InputStreamReader

d)

FileReader

8.

In an XML configuration file, what bean tag attribute do you use to ensure that the bean definition creates different managed bean instances per request?

a)

it’s the default there is no need to add an attribute

b)

scope=request

c)

scope=prototype

d)

scope=singleton

9.

Constructor argument resolution in an XML file can be achieved by; pick all that apply.

a)

Type

b)

Index

c)

Constructor name

d)

Order within type

10.

XML configuration file tags and grammar is controlled by; pick all that apply.

a)

Java jars

b)

Schemas

c)

Namespaces

d)

Java code

11.

You are to define a bean definition getServiceBean() in a Java configuration class for EmployeeServiceImpl with a name of "emplService" and a public initializer method of "init". Which is a correct approach to doing this?

a)

@Bean(name="emplService") and execute the init() method inside the Bean definition method itself before returning the service bean

b)

All of the above

c)

@Bean(name="emplService") and annotate method "init" in EmployeeServiceImpl with @PostConstruct

d)

@Bean(name="emplService", init-method="init")

12.

Using annotations, how could you inject a bean that implements the interface EmployeeDao, whose id is "emplDao", into a Spring-managed bean of "employeeService"? Assume that there are multiple beans that implement EmployeeDao in your application and you are annotating the property employeeDaoImpl (field).

a)

@Value("emplDao")

b)

@Autowired (name="emplDao")

c)

@Resource(name="emplDao")

d)

@Named("emplDao")

13.

You are writing a JUnit test class for your application using a Java configuration class AppConfig, and it is also to have an Initializer (the class MyInitializer) where you have tailored system properties for use in the test. Which is the annotation approach that you will take?

a)

@ExtendWith(SpringExtension.class) and @ContextConfiguration(classes=AppConfig.class)

b)

@ExtendWith(SpringExtension.class) and @ContextConfiguration(locations=AppConfig.class, initializer=MyInitializer.class)

c)

@ExtendWith(SpringExtension.class) and @ContextConfiguration(classes=AppConfig.class, initializer=MyInitializer.class)

d)

@ExtendWith(SpringExtension.class) and @ContextConfiguration(classes=AppConfig.class, initializer="MyInitializer")

14.

Which of the following is false about JSR 250 @Resource annotation?

a)

Can be used on constructors

b)

Can only be used on setters

c)

Is not a Spring Annotation

d)

Does the same as @Autowired as it can try to resolve a bean by-type

15.

We mentioned that after setter injection in a bean lifecycle, we can define an initializer by implementing what interface?

a)

ApplicationContextAware

b)

DisposableBean

c)

InitializingBean

d)

BeanPostProcessor

16.

What were the motivations behind Java Configurations; pick all that apply.

a)

Externalize the configuration

b)

Compile time checking

c)

Get rid of XML

d)

Type Safety

17.

What annotation can we use for simple value injection.

a)

@Component

b)

@Value

c)

@Configuration

d)

@Scope

18.

What tag from the context namespace do you use to register the BeanPostProcessors that scan for annotations or spring managed bean.

a)

property

b)

component-scan

c)

annotation-config

d)

bean

19.

Which annotation do you use @Qualifier with.

a)

@PostConstruct

b)

@Resource

c)

@Autowired

d)

@Inject

20.

What Design Pattern does the Spring DispatcherServlet implement.

a)

FrontController

b)

Proxy

c)

Model

d)

Model View Controller

21.

What are Spring Boot Starter dependencies? Select all that apply.

a)

Application dependencies that “drag” in the actual jars for the Spring Boot Application

b)

They build and define the starter project structure for a Spring Boot Application

c)

They contain no code of their own but are virtual dependencies

d)

The core dependencies that provide the basis of a Spring Boot Application

22.

Under which directory would you find configuration files in a Spring Boot Project using all default configurations.

a)

src/main/resources/static

b)

src/main/resources/js

c)

src/main/resources/template

d)

src/main/resources/config

23.

What annotations does the single annotation @SpringBootApplication on a SpringBootApplication runnable class replace to automatically configure a WebApplicationContext including the DispatcherServlet and auto scanning for Controllers? Choose the three that apply.

a)

@Autowired

b)

@Configuration

c)

@ComponentScan

d)

@EnableAutoConfiguration

24.

Why are @ConfigurationProperties annotated Java classes preferred over @Value (“${…}”) when it comes to injecting items in from the Spring Environment? Select all that apply.

a)

Can populate complex objects

b)

Validated

c)

Type Safe

d)

Just injecting into a Controller as a Java Dependency i.e. the class and not a Spring annotation dependency

25.

What annotation must you place upon a class to be picked up by Spring Boot package-based component scan to be part of the DispatcherServlet HandlerMappings matching URL to method in such a class.

a)

@GetMapping

b)

@SpringBootApplication

c)

@RestController

d)

@Configuration

26.

What annotation must you place upon a method in a RestController class to be tied to an HTTP GET.

a)

@Configuration

b)

@SpringBootApplication

c)

@GetMapping

d)

@RestController

27.

What annotations does the @SpringBootApplication annotation replace.

a)

@ComponentScan

b)

@EnableAutoConfiguration

c)

@SpringBootConfiguration

d)

@RestController

28.

What notation format can we use to define parent–child relationships in configuration files to populate the Spring Environment object.

a)

Properties i.e. key value pairs

b)

Java

c)

Yaml

d)

text

29.

Spring MVC uses what to invoke RestController methods and convert request parameters and response payloads through provided converters.

a)

HandlerMappings

b)

HandlerAdapters

c)

ViewResolvers

d)

ExceptionHandlers

30.

How would you inject into a Controller method an optional parameter from the request, i.e. url? id=55 where the id parameter may or may not be present.

a)

Annotate the method argument with @RequestParam("id") int id

b)

Annotate the method argument with @PathVariable("id") Optional<Integer> optional

c)

Annotate the method argument with @RequestParam("id") Optional<Integer> optional

d)

Annotate the method argument with @PathVariable("id") int id

31.

When accessing a REST service at url /abc with an HTTP GET, using RestTemplate, what method would you use to get at the response body immediately.

a)

String string = new RestTemplate().getForObject(abc, String.class);

b)

ResponseEntity responseEntity = new RestTemplate().exchange("/abc", HttpMethod.GET, null, String.class);

c)

ResponseEntity entity = new RestTemplate().getForEntity(abc, String.class);

d)

String string = new RestTemplate().exchange/abc, null, String.class);

32.

What attribute would you add to a @GetMapping("/") annotated RestController method to return XML or JSON.

a)

@GetMapping("/")

b)

@GetMapping(path="/", produces=MediaType.APPLICATION_XML)

c)

@GetMapping(path="/", produces={MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE})

d)

@GetMapping(path="/", consumes={MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE})

33.

How can you extract the header "user-agent" out of the request in a RestController method, to be available in that method for processing.

a)

@RequestHeader("user-agent") String agent

b)

@PathVariable("user-agent") String agent

c)

@RequestParam("user-agent") Optional<String> optional)

d)

  @RequestHeader("user-agent") Optional<String> optional)

34.

How can you extract the request payload and inject it into a RestController method for processing

a)

@RequestBody

b)

@RequestParam

c)

@Pathvariable

d)

@Header

35.

Who creates the Model object

a)

HandlerAdapter

b)

DispatcherServlet

c)

ViewResolver

d)

HandlerMappings

36.

Attributes in the Model are passed through to the request and then that object is dispatched to the selected view. If I place in the Model an attribute i.e. model.addAttribute("message", "hello"), how can I access that in a Thymeleaf web page

a)

${message}

b)

${model.getHello()}

c)

${hello}

d)

message

37.

How would I define the port of a Spring boot application if I did not want the default 8080 but 8081

a)

In the application.yaml file enter the key value pair of port=8081

b)

Place the attribute "port" the @Controller annotation

c)

In the application.properties file enter the key value pair of server.servlet.context-path=8081

d)

In the application.properties file enter the key value pair of server.port=8081

38.

What is the @RequestMapping annotation used for

a)

It identifies what the payload is for a Request

b)

It defines the Response types from a Controller

c)

It defines the Url relationship between a Controller and an HTTP Request and can be placed at the Class level or method level.

d)

It annotates the class as a Controller

39.

How does Spring Boot wire up the WebApplicationContext components (select all that apply)

a)

The WebApplicationContext components are dragged into your application via Spring boot Starters in the pom.xml

b)

It has a series of opinionated defaults that without further enhancement will render a WebApplicationContext

c)

You can override these defaults

d)

You have to code up the dependencies yourself

40.

Using Annotations, how could you annotate a JPA EntityManager of a Spring managed bean to provide Transactionally based interactions with a database?

a)

@PersistenceContext

b)

@PersistenceUnit

c)

@Inject

d)

@Value("#{entityManager}")

41.

How would you provide an implementation of the Spring data JpaRepository to? inject into your Spring managed beans? Pick all that apply.

a)

Create a class that extends JpaRsepository and provide implementations of its methods

b)

Provide a class that extends EntityManager an inherit its methods

c)

Create an interface that extends JpaRepository

d)

Provide the maven dependency for spring-boot-starter-data-jpa in your pom

42.

How do you Annotate a Repository to be a Restful service itself where json collections is wrapped in the element "course" and its url is "/courses"?

a)

@RepositoryRestResource(collectionResourceRel = "course")

b)

@RestController

c)

@RepositoryRestResource(collectionResourceRel = "course", path = "courses")

d)

@RepositoryRestResource

43.

How would you define a query method in a JpaRepository to get all students by their firstName and lastName by equality and return a Collection of Students

a)

Collection findByFirstNameEqualAndLastNameEqual(String s1, String s2);

b)

Collection getByFirstNameAndLastName(String s1, String s2);

c)

Collection findByFirstAndLast(String s1, String s2);

d)

Collection findByFirstNameAndLastName(String s1, String s2);

44.

What annotation defines a class as a subset of a JPA Entity Resource when exposing a JpaRepository through REST

a)

@Projection

b)

@Component

c)

@Controller

d)

@Entity

45.

In Aspect Oriented Programming using Spring, what is a Joinpoint?

a)

A class that implements enterprise application concerns that cut across multiple classes

b)

Defines an expression that represents and entry point into the application

c)

Defines additional behavior to apply when a method is executed in the application

d)

Defines when an Advice should be applied, such as a method invocation

46.

When would you use an @Around advice? Select all that apply.

a)

To change the return object from a target bean

b)

To get at the target method arguments

c)

To catch and log Exceptions and force a throw of a more general Exception

d)

To block access to a target bean

47.

Which Advice would you use to always log the return from a target bean method execution.

a)

@AfterReturning

b)

@After

c)

@Before

d)

@AfterThrowing

48.

How would you annotate a method to Guarantee that it will run in its own transaction and rollback on a CheckedException

a)

@Transactional

b)

@Transactional(noRollbackFor = CheckedException.class, propagation =Propagation.REQUIRES_NEW)

c)

@Transactional(propagation= REQUIRED)

d)

@Transactional(noRollbackFor = CheckedException.class, propagation =Propagation.REQUIRED)

49.

What are cross-cutting concerns in Spring AOP

a)

Behavior which we want to have in a core business modules of an application

b)

Behavior that is External to the application

c)

Behavior in one class only

d)

Behavior which is applicable throughout the application

50.

What does the yaml configuration property in a eureka Service, eureka.instance.leaseExpirationDurationInSeconds define?

a)

Eureka is to advertise the IP addresses of services rather than their hostnames.

b)

Removes, a service from the Eureka Registry after the Eureka Service has not received 3 consecutive missing heartbeats of the desired number of seconds.

c)

The host name of the Eureka Service.

d)

The period between heart beats from registered services to the Eureka instance to inform Eureka that the service is still available.

51.

Which annotation enables you to register a service with a running Eureka Service?

a)

@EnableDiscoveryClient

b)

@EnableEurekaServer

c)

@RibbonClient

d)

@EnableZuulProxy

52.

Which annotation enables you to launch a running Eureka Service, ready to accept registration?

a)

@EnableEurekaServer

b)

@EnableDiscoveryClient

c)

@RibbonClient

d)

@EnableZuulProxy

53.

Which of the following is not an independent objective of a Microservice architecture?

a)

Deployable

b)

Scalable

c)

A monolithic executable component

d)

Replaceable

54.

Spring Cloud Netflix provides Netflix OSS integrations for Spring Boot apps through auto configuration for binding to the Spring Environment. What org.springframework.cloud artifact enables this to happen?

a)

spring-cloud-starter-feign

b)

spring-cloud-starter-hystrix

c)

spring-cloud-starter-ribbon

d)

spring-cloud-starter-eureka-server

55.

Which of the following best describes Service Discovery?

a)

Maximize the availability of a service across multiple servers.

b)

The client is responsible for determining network locations by querying a service registry.

c)

A service that controls the flow of scaled service instances.

d)

Prevent an application from repeatedly trying to execute an operation that's likely to fail.

56.

Which type of Service in Netflix OSS is used to provide client side load balancing for services to delegate to other services?

a)

Ribbon

b)

Feign

c)

Zuul

d)

Eureka

57.

What type of filters can a Zuul service provide? (Select all that apply)

a)

EXCEPTION

b)

LOGGING

c)

ROUTING

d)

PRE

58.

Which Netflix OSS project provides functionality for stopping cascade failures across services by implementing the circuit Breaker Pattern?

a)

Hystrix

b)

Zuul

c)

Ribbon

d)

Feign

59.

Which Netflix OSS project provides functionality for Routing services?

a)

Hystrix

b)

Feign

c)

Zuul

d)

Ribbon

60.

Which of these annotations are JSR330

a)

  @Override

b)

@Inject

c)

@Resource

d)

@Autowired