Skip to content

Instantly share code, notes, and snippets.

@bytestree
bytestree / CustomAuthenticationFailureHandler.java
Last active November 22, 2019 16:32
UserService to return UserDetails object on authentication and implementation of AuthenticationSuccessHandler and AuthenticationFailureHandler
@Component("customAuthenticationFailureHandler")
public class CustomAuthenticationFailureHandler extends SimpleUrlAuthenticationFailureHandler {
private String DEFAULT_FAILURE_URL = "/login?error";
@Autowired
private UserService userService;
@Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
@bytestree
bytestree / Application.java
Last active December 21, 2016 14:46
pom file to create RESTful Web Services using Spring Boot and PostgreSQL
package com.bytestree.restful;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
@bytestree
bytestree / EmployeeController.java
Last active December 21, 2016 14:32
Restful Web Service Controller for CRUD operations
package com.bytestree.restful.controller;
import java.util.Arrays;
import java.util.List;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
@bytestree
bytestree / CRUDService.java
Created September 11, 2016 19:29
Service layer for Restful Web Service using CRUDService interface for CRUD operations.
package com.bytestree.restful.service;
import java.io.Serializable;
import java.util.List;
public interface CRUDService<E> {
E save(E entity);
E getById(Serializable id);
@bytestree
bytestree / Employee.java
Created September 11, 2016 20:43
Repository class for Employee entity using Spring Data JPA
package com.bytestree.restful.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@bytestree
bytestree / pom.xml
Created May 7, 2016 12:51
Hibernate Generic DAO dependencies
<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>com.bytestree.hibernate</groupId>
<artifactId>generic-dao-hibernate</artifactId>
<version>1.0.0-SNAPSHOT</version>
<properties>
<spring.version>4.2.5.RELEASE</spring.version>
<hibernate.version>4.3.11.Final</hibernate.version>
@bytestree
bytestree / Employee.java
Last active May 7, 2016 23:46
Generic DAO in Hibernate - EmployeeDao.java using GeneticDao.java
package com.bytestree.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@bytestree
bytestree / MyApplication.java
Created May 7, 2016 21:40
Generic DAO in Hibernate - Application class
package com.bytestree;
import java.util.List;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.bytestree.model.Employee;
import com.bytestree.service.EmployeeService;
@Component
@bytestree
bytestree / TestApplication.java
Last active May 7, 2016 23:45
Generic DAO in Hibernate - Client Application
package com.bytestree;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import com.bytestree.config.AppConfiguration;
public class TestApplication {
public static void main(String[] args) {
// Load the Spring context and beans
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfiguration.class);
@bytestree
bytestree / AbstractGenericDao.java
Last active May 7, 2016 14:59
Generic DAO in Hibernate interface and abstract implementation
package com.bytestree.dao;
import java.io.Serializable;
import java.lang.reflect.ParameterizedType;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Example;
import org.springframework.beans.factory.annotation.Autowired;