Skip to main content

Posts

Showing posts with the label Spring

Spring Certificate Study Notes

#1 constructor Injection vs properties Inject constructor: pro: accountRepository promote immutation; concise; constructor-arg can be in any order con: optional; describle; inherited automatically; cyclic references; #2 How to implement factory bean:  factory-method;  implement FactoryBean interface and the getObject() method (Auto-Detected by Spring Framework) #3 @PostConstruct  and @PreDestory @PostConstruct can be used to add behavior at startup after spring finishing initiating the bean object @PreDestory before bean object being destored. The alternative in the xml configuration are init-method and destory-method Best practice: #1 Separate 'application" beans from "infrastructure" beans as infrastructure of changes between environments.

Spring MVC Handler Interceptor example

source: http://www.mkyong.com/spring-mvc/spring-mvc-handler-interceptors-example/ Spring MVC allow you to intercept web request through handler interceptors. The handler interceptor have to implement the  HandlerInterceptor  interface, which contains three methods : preHandle()  – Called before the handler execution, returns a boolean value, “true” : continue the handler execution chain; “false”, stop the execution chain and return it. postHandle()  – Called after the handler execution, allow manipulate the ModelAndView object before render it to view page. afterCompletion()  – Called after the complete request has finished. Seldom use, cant find any use case. In this tutorial, you will create one handler interceptor to show the use of the  HandlerInterceptor . MaintenanceInterceptor  – Intercept the web request, check if the current time is in between the maintenance time, if yes then redirect it to maintenance page. Note It’s reco...