Spring Flashcards
A bean is a Singleton because…
Only one of them are created. We can call it several times, but only one new is created one time.
IT IS A GOOD THING :D
5 Scopes available to configure a bean
Singleton
Prototype
+ valid in only web-aware projects:
Request
Session
Global
Scope: Prototype and bean
A new bean per request.
You would rather have a singleton
Scope: Singleton and bean
Restricts the instantiation of a class to just one object.
Is the default bean scope inside of spring
= One instance per spring container or context
Scope: Request and bean (web)
Returns a bean per request. short lived bean
Scope: Session and bean (web)
Returns a bean per session. The bean lives as long as the session.
Scope: Global session and bean (web)
returns a bean per application. Once i access the bean, it’s alive as long as the application lives on the server
Stereotype Annotations
@Component (same thing as @Bean)
@Repository (Used to denote a class that is used as a repository object)
@Service (confusing, because service does not mean webservice or microservice. This is where you put your business logic)
Can “@Bean” be used at class level?
No, only on method level. If you wanna use it on Class level, use @Component
Session Locale resolver
Ties our session to a locale
What do you need to internationalize a Spring MVC app?
LocaleInterceptor
Where do you store your files to avoid deep linking?
src, main, java, WEB-INF
What piece of configuration is used to locate files and serve them to the UI?
ViewResolver
What annotation is used to accept an object in the parameters of a method in Controller?
@ModelAttribute
What are the four parts that make up Spring MVC Configuration?
pom.xml, Config, Java, View
What are the components of Spring?
Service, Repository, Controller
What do RestControllers bypass and instead return a body?
ViewResolver
What technique is used to help with form resubmission errors?
Post-Redirect-Get
What does the most common Controller configuration return to locate the view?
A String representing the view name
Spring recommends not serving up what view technology from self-contained JARs?
JSP pages