Skip to content

Instantly share code, notes, and snippets.

View iamitshri's full-sized avatar
🦉
Focusing

iamitshri iamitshri

🦉
Focusing
View GitHub Profile
@iamitshri
iamitshri / configDemo.java
Last active November 18, 2018 21:47
Spring boot feature :- Configuration Properties demo
@Component
@Data
@ConfigurationProperties(prefix = "config.demo")
@Validated
public class ConfigPropertiesDemo {
int numTests;
@Size(min=3)
String name;
float expense;
boolean booleanYes;
@iamitshri
iamitshri / notes-jpa.md
Last active November 11, 2018 01:35
JPA Notes

Efficient JPA Querying

MultipleBagFetchException

  • Caused by: org.hibernate.loader.MultipleBagFetchException: cannot simultaneously fetch multiple bags: [com.jpa.experiments.entity.TaskEntity.aspects, com.jpa.experiments.entity.AspectEntity.anchors]
@iamitshri
iamitshri / JPA mysql springBoot.properties
Last active July 7, 2019 19:44
Spring Boot JPA configuration
spring.datasource.url=jdbc:mysql://host:3306/dbname?autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull&useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
spring.datasource.username=username
spring.datasource.password=password
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=none
@iamitshri
iamitshri / AsyncTaskExecutorSpringBoot.java
Created October 11, 2018 02:58
Execute tasks in spring
package edu.wgu.dm.datagenerator;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Future;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@iamitshri
iamitshri / RestResponseEntityExceptionHandler.java
Created October 9, 2018 21:43
Spring Boot Exception Handler that parses Response status annotation on the Exception class
package edu.wgu.dm.config;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
@iamitshri
iamitshri / annotationReflectionExample.java
Created October 9, 2018 21:02
Read Annotations on class using Reflection
// Get annotations on the class object
Annotation[] annotations = classobject.getClass()
.getAnnotations();
for (Annotation annotation : annotations) {
log.debug("annotation type: {}", annotation.annotationType());
Class<? extends Annotation> type = annotation.annotationType();
for (Method method : type.getDeclaredMethods()) {
Object val = method.invoke(annotation, (Object[]) null);
log.debug("method name: {}, return value:{} return type:{}", method.getName(), val, val.getClass()
.getName());
@iamitshri
iamitshri / eclipse plugins.txt
Last active October 8, 2018 17:04
Eclipse STS source code analysis tools for java
static code analysis tools
Unnecessary Code Detector
https://marketplace.eclipse.org/category/free-tagging/find-unused-code
Findbugs
https://marketplace.eclipse.org/content/findbugs-eclipse-plugin
spotbugs
@iamitshri
iamitshri / commands.txt
Last active October 5, 2018 17:15
Maven Commands that I want to remember
What do these option means?
-B -f pom.xml -X clean install
@iamitshri
iamitshri / setting the default time zone.java
Created September 11, 2018 16:26
Setting the default timezone for spring boot app
@PostConstruct
void started() {
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
}