intellij junit working directory

if the working directory for junit test is not properly set, the resource file might not be able to be loaded if relative path is used. By default, Intellij uses project path as working directory. However if you have sub-modules which are in the sub directories, the junit test might have problem running locally. To…

Java Thread Local

Thread Local is an interesting and useful concept, yet most of the Java developers are not aware of how to use that. In this post, I’ll explain what is Thread Local and when to use it, with an example code. Since it’ll be little tough to understand this concept at first, I’ll keep the explanation…

Spring mvc HandlerMapping VS HandlerAdapter AND mvc:annotation-driven

HandlerMapping and HandlerAdapter HandlerMapping and HandlerAdapter are good for rest service testing. The strategy interface HandlerAdapter takes the role of invoking handler methods selected by some HandlerMapping. If a HandlerMapping selects a controller, but not a specific method, then the HandlerAdapter also selects the handler method. DispatcherServlet invokes controllers through HandlerAdapter strategy objects. This allows…

could not initialize proxy – no Session

All java web frameworks have one or more servlets that handle the requests. The servlet handles each request (HttpRequest) by creating a new thread that will finally produce the response (HttpResponse). The method that processes each request is executed inside this thread. At the beginning of the request processing your application should allocate the resources…

Secrets of the Spring AOP Proxy

Spring Aspect Oriented Programming (AOP) is a powerful mechanism to weave cross cutting concerns like security, transactions, exception handling, logging, etc. into business code (“core concerns”) without explicitly adding calls to the cross cutting concern.  This allows the cross cutting concern to be updated, removed, swapped out, and generally maintained in a much simpler fashion….

JAVA Output Alignment

The printf function works fine for space padding. For example: // % – insert argument value // , – insert locale-specific separators // 20 – pad out to 20 spaces // .2 – fix precision at two decimal places // s – string argument // f – float argument System.out.printf(“%20s %20s\n”, “Column 1”, “Column 2”); System.out.printf(“%,20.2f %,20.2f\n”,…

how Spring finds applicationContext xml

Spring can be easily integrated into any Java-based web framework. All you need to do is to declare the ContextLoaderListener in your web.xml and use a contextConfigLocation <context-param> to set which context files to load. The <context-param>: <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext*.xml</param-value> </context-param> The <listener>: <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> NOTE: Listeners were added to the Servlet API in version 2.3. If you have a Servlet…