SpringMVC4 + Spring Data JPA + SpringSecurity configuration using JavaConfig

In this article we will see how to configure and integrate SpringMVC4, Spring Data JPA with Hibernate and SpringSecurity using JavaConfig. 1. First let’s configure all the necessary dependencies in pom.xml 4.0.0 com.sivalabs springmvc-datajpa-security-demo 1.0 war 1.7 4.11 1.7.5 1.0.13 4.0.0.RELEASE 1.4.1.RELEASE 3.2.0.RELEASE 4.2.6.Final 1.7.2 5.1.26 2.3.1 1.2.2 3.1 ${project.artifactId} org.apache.maven.plugins maven-compiler-plugin 3.1 ${java.version} ${java.version} org.slf4j jcl-over-slf4j ${slf4j.version} org.slf4j slf4j-api ${slf4j.version} ch.qos.logback logback-classic ${logback.version} org.springframework spring-context-support commons-logging commons-logging org.springframework spring-webmvc org.springframework spring-test org.springframework.data spring-data-jpa ${spring-data-jpa.version} org.hibernate hibernate-entitymanager ${hibernate.version} org.springframework.security spring-security-core ${spring-security.version} org.springframework.security spring-security-web ${spring-security.version} org.springframework.security spring-security-config ${spring-security.version} org.springframework.security spring-security-taglibs ${spring-security.version} org.aspectj aspectjweaver ${aspectj.version} org.aspectj aspectjrt ${aspectj.version} junit junit ${junit.version} test

Continue reading »

Context root relative URLs using Spring’s

While developing web applications the common problem is to reference the static resources like js, stylesheets,images in JSPs from the relative URLs.Suppose in your project you have the following structure.MyApp        src        WebContent              home.jsp              jsp                  createUser.jsp              js                  util.js              css                   style.css              images                      logo.jpg             WEB-INF                          …             ……. So here if your current URL is http://localhost:8080/MyApp/home.do, you need to reference static resources as follows: <script type=”text/javascript” src=”js/util.js”/> Suppose your current

Continue reading »

How to POST and GET JSON between EXTJS and SpringMVC3

After one month of evaluation of the frameworks and tools, i choose ExtJS for UI and Spring/SpringMVC for business layer for my pet project. Again by using ExtJS we can send data to server by form submits or as request parameters or in json format through Ajax requests. ExtJS uses JSON format in many situations to hold data. So I thought using JSON as data exchange format between EXTJS and Spring will be consistent. The following code snippets explains how we can use ExtJS and SpringMVC3 to exchange data in JSON format. 1. Register MappingJacksonHttpMessageConverter in dispatcher-servlet.xml <bean class=”org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter”> <property

Continue reading »

Spring+Hibernate Application with zero XML

Spring framework came up with Annotation support since 2.5 version which eases the development.Whether Annotation based approach better or XML approach is better is depends on the project and their personal preference. Let us see how we can write a Simple Application using Spring and Hibernate using Annotations, no xml at all. The configuration for JDBC datasource and Hibernate properties: application.properties ################### JDBC Configuration ##########################jdbc.driverClassName=org.hsqldb.jdbcDriverjdbc.url=jdbc:hsqldb:file:db/SivaLabsDB;shutdown=truejdbc.username=sajdbc.password=################### Hibernate Configuration ##########################hibernate.dialect=org.hibernate.dialect.HSQLDialecthibernate.show_sql=truehibernate.hbm2ddl.auto=updatehibernate.generate_statistics=true We can instantiate ApplicationContext from a java file having @Configuration annotation. AppConfig.java package com.sivalabs.springmvc.config;import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.context.annotation.Import;import org.springframework.core.io.ClassPathResource;/** * @author SivaLabs * */@Import({RepositoryConfig.class})@Configurationpublic class AppConfig{    //    @Bean    public PropertyPlaceholderConfigurer getPropertyPlaceholderConfigurer()    {        PropertyPlaceholderConfigurer ppc

Continue reading »