Tag: Spring MVC

Hi All, these days most of the people are asking me how to execute Spring Security in their Applications, as i did not worked on it, i thought of implementing myself, and here is the outcome(this post).Sometimes you need to secure our application page from unauthorized access. In the below example, we will ensure secure URL access by providing custom Login form . User need to provide correct login credential to view the page.

In above congratulation, the /admin and sub-folders of it are all password protected.Cross Site Request Forgery (CSRF) Protection, If CSRF is enabled, you have to include a _csrf.token in the page you want to login or logout.

Hello all, in this post i am going to take you on a tour how to render fusion charts data dynamically. In my previous post i explained rendering data statically. Here i explain how to make Ajax calls, using ajax we are going to populate region,country. Based on the region and country we get the oilConsumedByCountry by year and change this data based on the country changed, and create a dashboard which displays “Pie and Bar” charts.

*Note: This post assumes you already downloaded FusionCharts API and Maven
Following is the script for creating db table.

Hello all, from past few days i was working on some reports and dashboards so the requirement is to call some spring services, which return the data in the form of JSON. my responsibility is to receive the JSON data and feed it to correct chart and render it so im here to share my experience in the form of small example.

After this step please extract the downloaded FusionChartsXT.zip in desired location, from that navigate to the folder charts, copy all the swf files and put them in the charts folder of your eclipse(src/main/webapp/charts)
now again from the FusionChartsXT home copy “FusionCharts.js,Jquery.min.js” and put them in javascript folder of your eclipse.
Now it’s time to code logic.Lets integrate Spring and Hibernate to query the database and here i transform the
result from database to JSON format, and return that to JSP.

Note: please create separate packages for interfaces and their implementations as it gives the project a clear separation between layers(good practice)

Hi all here is my post regarding integration of some of the best frameworks available in the market, Spring+JPA/Hibernate.Spring’s Basic concept: Inversion of Control

The basic concept of spring is the Inversion of Control pattern (dependency injection). In Spring, programmers don’t need to create user objects but they need to describe how they should be created (in applicationContext.xml or using annotations). Programmers need not directly connect components and services together in code but describe which services are needed by which components in a configuration file or using annotations. The spring container is responsible for all this. Spring creates all the objects, connects them together by setting the necessary properties, and determines when methods will be invoked.
So using Spring framework the integration between technologies become loosely coupled.

The Entity classes
The DAO class which will contain common db operation code and functions
The service class – which is the actual business class.. This will contain actual business logic in it. In our example, we save Credentials bean information using this class.Explained in the next tutorial
The client – The client can be a jsp / jsf web components or it can be a simple java program, which gets the service bean from spring and calls business method.
The spring’s applicationContext.xml descriptor which specifies what are the objects to be created when starting the application and where they should be injected.

Let’s go through the tutorial step by step.You can download the full project code at the end of the tutorial:
i explain how to Retrieve and Insert and leave Delete and Update to be coded yourself(for fun).

Step1:create a maven project in eclipse.
step2:update the pom.xml file as shown below.

Step5:lets code our second configuration file “spring-context.xml” which internally imports one more configuration file “controllers.xml”, this spring-context.xml file goes as a parameter for DispatcherServlet class of Spring framework.

Now its time to code our core database logic. The database logic is handled by JPA EntityManager, the object is injected into the EntityManager using the @PersistenceContext annotation its the responsibility of the Spring container to inject the EntityManager Implementation object after it scans the annotation. We will code the dao layer same as we did with service layer with an interface and its implementation class. please note that the dao is annotated as @Transactional that means the database operations will be executed under a transactional context
when spring scans the annotation.

Now its time to code controller which is responsible for deligating the requests to service layer and there to dao layer. In the retrieve method the response returned from the method will be a JSON String

Hi all in the previous post i have shown you how to create a mavenized Spring MVC Project with full configuration in that the Spring controller is returning a JSON String, now this is the string we want to collect in android client by calling it using Spring-Rest-Template.

The Jar files required for this application are
android-support-v4.jar
spring-android-auth-1.0.0.RELEASE.jar
spring-android-core-1.0.0.RELEASE.jar
spring-android-rest-template-1.0.0.RELEASE.jar

For JSON Support add the following jar files
jackson-core-asl-1.9.11.jar
jackson-mapper-asl-1.9.11.jar

Hi All, This time i had very tough time to show my proof of concept to one of my colleague regarding java Spring mvc and Android. the requirement is quite direct we have to create a Spring MVC project and deploy it to server and call the spring controller using Android Activity. Thanks to spring it has released Spring-rest-template api using which we can call the business logic that is deployed in the server as spring controller. so here is my example code to you how to call spring mvc using Android Rest Client

in this part i will be explaining u how to create a spring mvc project using maven dependencies.

Note: dont code network related logic in the main thread of android activity it will lead to android.os.NetworkOnMainThreadException

now that we have completed our configuration its time for us to write the model classes and business logic for handling requests from android client and return responce. Here we use JSON for communication layer. notice that you put the code in appropriate packages.
source code for controller

now its time to test the application open cmd and navigate to the project folder and issue “mvn clean install package”
without quotes it will download all jar files needed by your application and it builds the war file(bueauty of maven)
now your project is ready for deployment issue the command “mvn tomcat:run” without quotes your tomcats starts and your war will be deployed now your Spring MVC project is up and running lets see how to code Android REST client and communicate with Spring Web App in Part-II.