Skip to main content


Showing posts from July, 2014

Spring Certificate Study Notes

#1 constructor Injection vs properties Inject
promote immutation;
constructor-arg can be in any order

inherited automatically;
cyclic references;

#2 How to implement factory bean:
 implement FactoryBean interface and the getObject() method (Auto-Detected by Spring Framework)

#3 @PostConstruct  and @PreDestory
can be used to add behavior at startup after spring finishing initiating the bean object
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.

plumbing, a term in programming world

I often saw word 'plumbing' in the technical related book and never really know what does it mean. Today, it seems that I found the answer myself.


plumbingThe technical term for the code that manages data structures, persistence, inter-computer communications, database access etc. — all the technical details that are very necessary for an application to work, but are not application specific.
By analogy, just as plumbing and electrical wiring is normally hidden from view behind the walls of a house, so ideally should such plumbing be hidden away in library classes so it does not clutter up application-specific code.

Jpa concepts

If there's one thing you have to understand to successfully use JPA (Java Persistence API) it's the concept of aCache. Almost everything boils down to the Cache at one point or another. Unfortunately the Cache is an internal thing and not exposed via the JPA API classes, so it not easy to touch or feel from a coding perspective.Here's a quick cheat sheet of the JPA world: A Cache is a copy of data, copy meaning pulled from but living outside the database.Flushing a Cache is the act of putting modified data back into the database.A PersistenceContext is essentially a Cache. It also tends to have it's own non-shared database connection.An EntityManager represents a PersistenceContext (and therefore a Cache)An EntityManagerFactory creates an EntityManager (and therefore a PersistenceContext/Cache)

Spring MVC Handler Interceptor example

source: 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 recommended to extend the HandlerInterceptorAdapter for the convenient…