WorksheetsCore Spring 5 - Test 9
Total questions: 50
Worksheet time: 2hrs 40mins
Create - PATH
Read - GET
Update - POST/PUT
Delete - DELETE
True
False
True
False
Only in com.whizlabs.component.scan
In com.whizlabs.component.scan and com.whizlabs.component.scan.questions
In com.whizlabs.component and com.whizlabs.component.scan
In all of the packages for the application
True
False
True
False
.JSON
.properties
.yml/.yaml
.xml
@Repository
@Bean
@Service
@Controller
Methods annotated with @PreDestroy are called before the destroy() method of the interface DisposableBean.
Methods annotated with @PreDestroy and @PostConstruct are always called, whatever the scope of the bean is.
Methods annotated with @PostConstruct are called after afterPropertiesSet() method of the interface InitializingBean.
Spring calls methods annotated with @PreDestroy and @PostConstruct only once.
Field injection using @Auwotowired annotation is achieved by using Java Refletion behind the scenes.
Private fields cannot be injected using the @Autowired annotation.
@Autowired uses the field name as a default qualifier.
@Autowired can be used inside methods to provide dependencies for local variables.
A database driver
spring-data-jpa.jar in your class path.
Database credentials(usually username and password)
URL connection
Adding @EnableGlobalMethodSecurity(securedEnabled = true) will enable method-level security.
No additional annotation should be added, method-level security is enabled out of the box.
Both @Secured and @PreAuthorize can use SpEL
To enable @PreAuthorize, @PreFilter, @PostAuthorize and @PostFilter prePostEnabled attribute of the @EnableGlobalMethodSecurity element that must be configured to have the true value.
Model
ServletResponse
Errors
ServletRequest
Read uncommitted
Serializable
Repeatable Reads
Read commited
True
False
Monitoring
Metrics
Live reloading of the code
Health-checks
Pointcut
Join point
Advice
Aspect
They can map a String(the logical name of the view) to a View
An application can have only one implementation of ViewResolver
An application can have more than one implementation of ViewResolver and we can control their priority
Spring Framework provides a ViewResolver implementation and we are not obliged to register one.
AnnotationConfigApplicationContext
ConfigurableWebApplicationContext
WebApplicationContext
AnnotationConfigWebApplicationContext
Exception and all of its subclasses
RuntimeException and its subclasses
Error and its subclasses
All of the above
metrics
loggers
health
info
4xx
5xx
3xx
2xx
Final methods can be advised.
Self-invation is not supported.
A subclass is generated for each proxied object.
CGLIB Proxy will intercept private method calls.
management.endpoints.web.exposure.include=beans
management.endpoints.web.exposure.include.beans=true
management.endpoints.web.exposure.include=*
management.endpoints.web.exposure.exclude.beans=false
Authentication
Credentials
Authorization
Principal
Every project must have a spring.factories file
If present, spring.factories is located in META-INF folder
spring.factories can be replaced with application.properties
spring.factories contains a list of auto-configuration class candidates
http://localhost:8080/city?name=Bangalore will map to the method cityMethod.
http://localhost:8080/city will map to the method cityMethod.
http://localhost:8080/city?cityName=Bangalore will map to the method cityMethod.
We can replace @ReqestParam(required=false) String city with @ReqestParam Optional<String> city without changing the logic
Unit test
Assertion
Integration test
System test
BeanFactoryPostProcessor is invoked after all the Spring Beans are created
BeanFactoryPostProcessor has a single method called postProcess
BeanFactoryPostProcessor does not create beans but it can access and alter the Metadata that is used to create beans
BeanFactoryPostProcessor is a Spring bean as well.
@Component
@Controller
@Autowired
@Service
Apache Tomcat
Apache Geronimo
Jetty
Undertow
True
False
True
False
@Transactional can be placed on top of getByIdPositive instead of RepositoryTests and the class logic will be the same
Both getByIdNegative and getByIdPositive will be executed in a transaction.
Transactions for all the tests which are executed in the RepositoryTests class will be rolled-back
We can add @Commit on top of RepositoryTests class to commit the transaction after each test execution
@Bean
@Autowired
@Inject
@Resource
@Configuration
@ComponentScan
@ContextConfiguration
@EnableAutoConfiguration
It must be the first parameter of an advice.
It is supported by all of the advice types in Spring AOP.
It can be used to retrieve the arguments of the join point(method arguments)
We can have only one Joinpoint argument.
application.properties
application.json
application.yaml
application.xml
@Mock
@MockBean
@Inject
@InjectMocks
Create an interface which extends any of Repository,CrudRepository,JpaRepository or PagingAndSortingRepository.
Create an interface which extends any of Repository,CrudRepository,JpaRepository or PagingAndSortingRepository.
Use @EnableJpaRepositories on top of your configuration class and point out the package to search for repositories.
Create a class annotated with @Entity that will be used by the repository.
A class can have any number of methods annotated with @PostConstruct.
A method that is anoteted with @PostConstruct must be private.
A method that is annotated with @PostConstruct must be final.
Method annotated with @PostConstruct is called after dependency injection is done.
Application context holds all of the bean definitions within your application.
ApplicationContext is an abstract class that implements the interface BeanFactory.
Application context manages beans lifecycle.
All of the above.
In configuration files - application.properties/.yaml
Through command line arguments using --debug argument when launching the application
Through Environment variables
Using logging specific configuration, for example logback-spring.xml
True
False
True
False
Read commited
Read uncommited
Repateable Reads
Serializable
Around advice(@Around)
After throwing advice(@AfterThrowing)
Before advice(@Before)
After (finally) advice(@After)
@WebMvcTest is a class level annotation
You can specify a single controller for @WebMvcTest to auto-configure
@WebMvcTest will create ApplicationContext that contains only web components
When using @WebMvcTest with JUnit 5 @ExtendWith(SpringExtension.class) must be used in order for the test class to work correctly
It scans and configures @Entity beans
It scans and configures Spring Data Repositories
It scans and configures @Service annotated classes
It configures in-memory embedded database
RowMapper
PreparedStatementCreator
ResultSetExtractor
RowCallbackHandler
