1. What are the main features introduced in spring 4?
Ans: Spring 4 has introduced many new features. Some of them are as follows.
1.
2.
3. Java 8 and hibernate 4.3 have been supported.
4. Different time zone in spring MVC has been supported.
5. Now spring supports websocket protocol.
6. Spring messaging supports STOMP protocol.
7. Spring security JUnit test module has been added with
@RestController = @Controller + @ResponseBody
3. What is the role of AsyncRestTemplate and ListenableFuture in spring 4?
1.
@RestController
annotation has been introduced for easiness to develop spring rest web service.2.
AsyncRestTemplate
has been added to develop rest web service.3. Java 8 and hibernate 4.3 have been supported.
4. Different time zone in spring MVC has been supported.
5. Now spring supports websocket protocol.
6. Spring messaging supports STOMP protocol.
7. Spring security JUnit test module has been added with
@WithMockUser
and @WithUserDetails
annotations.2. What is the use of @RestController annotation in spring 4?
Ans: Spring 4 has introduced@RestController
annotation that has replaced @Controller
and @ResponseBody
. In spring 4 rest web service development, our service methods need not to use @ResponseBody
.@RestController = @Controller + @ResponseBody
3. What is the role of AsyncRestTemplate and ListenableFuture in spring 4?
Ans:
2. Java configuration class should be annotated with
3. Spring controller class uses
4. To work with WebSocket, other protocol and JS library such as SockJS and STOMP Protocol are required.
@Test @WithUserDetails("ram") public void testFour() { userService.methodFour(); }
AsyncRestTemplate
can return the URL output asynchronously. ListenableFuture
is the return type which itself will return ResponseEntity
.4. What is the role of AsyncClientHttpRequestFactory and AsyncClientHttpRequest in spring 4?
Ans:AsyncClientHttpRequestFactory
returns the instance of AsyncClientHttpRequest
that represents client side asynchronous HTTP request. We use it as follows.5. How to use WebSocket in spring 4?
Ans: 1. Java configuration class implementsAbstractWebSocketMessageBrokerConfigurer
and we need to override its methods that are configureMessageBroker()
and registerStompEndpoints()
. 2. Java configuration class should be annotated with
@EnableWebSocketMessageBroker
with @Configuration
. 3. Spring controller class uses
@SendTo
annotation with @MessageMapping
at method level to declare result URL. 4. To work with WebSocket, other protocol and JS library such as SockJS and STOMP Protocol are required.
6. What is the role of @CacheConfig in spring 4?
Ans:@CacheConfig
is used at class level. It is used to set common cache related settings. All the methods annotated with @Cacheable
override the settings of @CacheConfig
.7. How to handle @Async exception in spring 4?
Ans: Spring 4 providesAsyncUncaughtExceptionHandler
that caches exception thrown by the method annotated with @Async
. We create a class implementing AsyncUncaughtExceptionHandler
.8. What is the role of @WithMockUser and @WithUserDetails annotation in spring 4 security JUnit test
Ans:@WithMockUser
annotation allows mock user at server side in spring security JUnit testing. There are username
and roles
attributes in @WithMockUser
annotation. We use it as follows.@WithUserDetails
annotation provides custom UserDetailsService
in spring security JUnit testing and we can use it as follows.@Test @WithUserDetails("ram") public void testFour() { userService.methodFour(); }