Saturday, September 1, 2012

What is Cross Cutting Concerns in Spring?

The majority of application we design will contain common functionality that spans across tiers and layers, such as Security, Caching, Logging, Transactions and more. These are called crosscutting concerns. "Concern" means logic/functionality. Since it affects the entire application, and should have been in one centralised location rather than scattered across application layers and tiers.

For example: You have application, which spans multiple layers say Controller, Service and DAO. You have a requirement to add the logging code to one of the DAO method, yes that's easy one, just go to that method, and add the logging code at the top of the method, then there is a requirement to add Security code to the same method, where you have added the logging, yes this also seems to easy, you just go to the method, and add the necessary security logic to the method after the logging. Now you got a requirement to extend this logic to all the layers(Controllers and Service) of that method, okay little tedious, but we are expert in copy and paste, we will copy the code from the DAO and paste it in Service and Controller, that's all done. But really what we have done is a dirty job.

Now, if they want this to be done in our entire system, little crazy now, already we have done a dirty job by doing a copy paste of DAO to Service and Controller, our code has been scattered, if we need to change, we have to update all the classes, it will not be a big deal if it is one or two classes, but for entire application it is a pain full job.

That's where we will be using the Aspect Oriented Programming (AOP) . It is a programming technique based on the concept of an Aspect. Aspect encapsulates cross-cutting logic, the basic infrastructure code which all application needs. What we are going to do is, we will take the logging and security code, and encapsulate it into a module for a reusable code.

Will soon publish a post on how to configure the AOP in Spring along with the Cross Cutting Concerns

Happy Programming ...!!!

Monday, August 27, 2012

What is ContextLoaderListener in Spring?

After a very long time, started refresh myself on spring framework, started with some sample web application got held up on the configuration ContextLoaderListener, what it really is, what was the use.
It is the Bootstrap listner to start up the Spring's root WebApplicationContext. All configuration which have been configured and loaded up during the startup, will be available throughout the application.

Mostly DB Configuration will be most one which can be seen
To register the listner, just add the below line to the web.xml
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
The class ContextLoaderListner will be found in the spring.jar, which can be found in the dist folder under spring bundle.

Happy Programming !!

Saturday, October 2, 2010

What is the difference between partial and render in Zend PHP?

A view script can be rendered in Zend using partial and render method. Every view script rendered by the view object, will have the entire variable scope of the script preceeding it. This will lead to some unwanted issues, when you want to re-use the script multiple times, or if you want to manipulate the variables, which will lead to other issues for the later scripts.
For example, you have a shared view script which is used to display the Ads in your index page, based on the position variable. Suppose in your index page, you are calling the Ads script in the top as well as bottom of your page, by using the render method and you have your position variable initialized to some value through controller and sticked on to the view, the the same value will be in scope throughout the script for the Ads call for both top and bottom, unless it is changed everytime before the shared Ads call is rendered, which will create some awkward issues in displaying the Ads. To overcome this issue
Enters partial: The big difference between rendering the script using partial and render is that, partial will have its own variable scope, it doesn't see any variables associated to the view, it only see the variable passed to it directly. As an example take the following

$this->Ads('/shared/viewAd.phtml', array('position' => "top", 'groupId' => '1223'));

Friday, September 10, 2010

How to bring MyComputer Icon in desktop in Windows 7


To bring the MyComput Icon in desktop in Windows7. Click the Start menu, and then right click on the "Computer". Click on the "Show on Desktop" item in the menu, and your computer icon will be back on the desktop.

Wednesday, August 25, 2010

Exception in thread "main" java.lang.NoClassDefFoundError: javax.persistence.Cacheable

When you are working with Hibernate using the Annotations, you will get the following exceptions
Exception in thread "main" java.lang.NoClassDefFoundError:javax.persistence.Cacheable 
even though you have added the required libraries that comes with the Hibernate distribution final 3.5 as well as ejb3-persistence.jar.
The reason for this javax.persistence.Cacheable is part of JPA 2.0 specification. To overcome this issue, you need to add the following JAR file hibernate-jpa-2.0-api-1.0.0.Final.jar, which will be available under /lib/jpa directory in Hibernate distribution.

Happy programming

Initial SessionFactory creation failed.org.hibernate.AnnotationException: java.lang.NoSuchMethodException

When you have the default libraries provided by the Hibernate 3.5 (hibernate-annotations.jar)and also have the ebj3-persistence.jar to support the annotation feature, you will be end up with the following exception on runtime
Initial SessionFactory creation failed.org.hibernate.AnnotationException: java.lang.NoSuchMethodException: org.hibernate.validator.ClassValidator.(java.lang.Class, java.util.ResourceBundle, org.hibernate.validator.MessageInterpolator, java.util.Map, org.hibernate.annotations.common.reflection.ReflectionManager)
This is because of the incompatible types, if you are using the EJB based Annotations feature just, remove the hibernate-annotations.jar from your library. This will resolve the above runtime exceptions.

Saturday, August 14, 2010

java.net.BindException: Address already in use: JVM_Bind 8009

In most of our development machines, we would have installed so many things for our practice purpose, which will create hell of issues, on the port number. So many of you, have encountered the following exceptions, when starting our server
java.net.BindException: Address already in use: JVM_Bind 8009.
How to figure out which application is occupying my port
In Windows
1. In MS-DOS, send command "netstat -ao". You can get network information for all processes.

2. Find out the one using port 8009, get the PID.
3. Find out the process with the PID you just got from windows task manager and shut it down. (By default the Task Manager doesn't show the PID. You have to add it from the menu View Select columns)
4. That's it, restart your server