Add global exception management in Rest web service

Since I adopted a Restful architecture, I need also a simple way for the exceptions management. With Spring, it can be easily set-up with in a central class, avoiding a painful management per service. To do this, we need to define a class with the @ControllerAdvice annotation, this class will be automatically associated to our… Continue reading Add global exception management in Rest web service

Define Restful web services using Spring

In one of my project, I had the difficult decision to switch to another technology: I replaced JSF with Angular-JS. Our goal was to speed up the development by removing the painful part implied with JSF, as a lot of server requests to manage, some view state issues, the refresh management, the need to implement… Continue reading Define Restful web services using Spring

Define configuration file outside of the classpath

Here I describe the way I use to configure my applications. The main idea is to define a property file outside of the application, doing this, it is possible to deploy the same application in several environments (dev/test/prod) without any changes. First of all, the property file: net.classnotfound.app.jdbc.server=db-server net.classnotfound.app.jdbc.port=1521 net.classnotfound.app.jdbc.sid=xe net.classnotfound.app.jdbc.user=scott net.classnotfound.app.jdbc.password=koala The tips is… Continue reading Define configuration file outside of the classpath

Spring MyBatis configuration

Here I describe the project configuration to use MyBatis as ORM and benefit of the transactions management provided by Spring. For that, we have to add the MyBatis-Spring library to the basic MyBatis. First, the Maven POM is like: <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.2.3</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>1.2.1</version> </dependency> And now, the Spring configuration file… Continue reading Spring MyBatis configuration

ThreadLocal usage

The ThreadLocal is very helpful to keep some information available from anywhere in the application but it is very important to release it when the process ends, otherwise, the resource will never be free and can cause a memory leak. Here is an example of using TheadLocal to store data in a web application. I… Continue reading ThreadLocal usage

My Eclipse shortcuts

Here is a list of my favorite shortcuts I use with Eclipse: [Ctrl]+[D]: Delete row [Ctrl]+[F]: Search in file [Ctrl]+[H]: Search->search… [Ctrl]+[O]: Navigation->Quick outline [Ctrl]+[Q]: Last edit location [Ctrl]+[S]: save the current tab [Ctrl]+[T]: Navigation->Quick type hierarchy [Alt]+[left/right]: Back/next to tab [Alt]+[up/down]: Move row [Ctrl]+[Shift]+[C]: Comment selection/uncomment commented selection [Ctrl]+[Shift]+[G]: Search->references->workspace [Ctrl]+[Shift]+[R]: Navigation->Open resource [Ctrl]+[Shift]+[S]:… Continue reading My Eclipse shortcuts

Published
Categorized as Java

Spring Security with JSF 2 and custom login form

Here, I am integrating Spring Security with JSF 2 using a custom login form. First, the maven dependencies for Spring-Security (I consider that the JSF project is already set-up, if it is not the case, you can check here): <properties> … <spring.security.version>3.2.4.RELEASE</spring.security.version> </properties> … <!– Spring-Security dependencies –> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-core</artifactId> <version>${spring.security.version}</version> </dependency> <dependency> <groupId>org.springframework.security</groupId>… Continue reading Spring Security with JSF 2 and custom login form

Change web context using Maven

<packaging>war</packaging> <build> <plugins> <plugin> <artifactId>maven-war-plugin</artifactId> <version>2.1.1</version> <configuration> <packagingExcludes>WEB-INF/web.xml</packagingExcludes> <warName>exp-elec-web</warName> </configuration> </plugin> </plugins> </build>

Maven config for JSF2/RichFaces

Here is my Maven configuration for a JSF2/Richfaces project: <project xmlns=”http://maven.apache.org/POM/4.0.0″ xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd”> <modelVersion>4.0.0</modelVersion> <groupId>net.classnotfound</groupId> <artifactId>jsf</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <name>jsf</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <org.apache.myfaces.version>2.2.0</org.apache.myfaces.version> <org.richfaces.version>4.3.5.Final</org.richfaces.version> </properties> <dependencies> <!– web container dependencies –> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.0.1</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>jsp-api</artifactId> <version>2.2</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.tomcat</groupId> <artifactId>tomcat-jasper</artifactId> <version>7.0.50</version> <scope>provided</scope> </dependency> <!– JSF dependencies –> <dependency>… Continue reading Maven config for JSF2/RichFaces