0
0
Spring Bootframework~10 mins

@Scope for bean scope in Spring Boot - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a singleton scoped bean using @Scope.

Spring Boot
@Component
@Scope([1])
public class MyService {}
Drag options to blanks, or click blank then click option'
A"prototype"
B"session"
C"request"
D"singleton"
Attempts:
3 left
💡 Hint
Common Mistakes
Using "prototype" instead of "singleton" for a singleton bean.
2fill in blank
medium

Complete the code to define a prototype scoped bean using @Scope.

Spring Boot
@Component
@Scope([1])
public class TaskProcessor {}
Drag options to blanks, or click blank then click option'
A"prototype"
B"application"
C"singleton"
D"session"
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing prototype with singleton scope.
3fill in blank
hard

Fix the error in the code to set the bean scope to session.

Spring Boot
@Component
@Scope([1])
public class UserSession {}
Drag options to blanks, or click blank then click option'
ASession
Bsession
C"session"
D"Session"
Attempts:
3 left
💡 Hint
Common Mistakes
Missing quotes around the scope name.
4fill in blank
hard

Fill both blanks to define a request scoped bean with proxy mode.

Spring Boot
@Component
@Scope(value = [1], proxyMode = [2])
public class RequestBean {}
Drag options to blanks, or click blank then click option'
A"request"
BScopedProxyMode.TARGET_CLASS
C"singleton"
DProxyMode.DEFAULT
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong scope value or proxy mode.
5fill in blank
hard

Fill all three blanks to define a session scoped bean with proxy mode and a custom bean name.

Spring Boot
@Component("[1]")
@Scope(value = [2], proxyMode = [3])
public class SessionBean {}
Drag options to blanks, or click blank then click option'
AcustomSessionBean
B"session"
CScopedProxyMode.TARGET_CLASS
D"prototype"
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to quote the scope or using wrong proxy mode.