Skip to content

Instantly share code, notes, and snippets.

@gilbertolptn
gilbertolptn / CustomErrorAttibutes.java
Created May 19, 2021
This classs replace default error attributes globaly on Spring MVC applications
View CustomErrorAttibutes.java
package com.example.demo.config;
import org.springframework.boot.web.error.ErrorAttributeOptions;
import org.springframework.boot.web.servlet.error.DefaultErrorAttributes;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.WebRequest;
import java.util.Map;
@Component
View RepositoryTestWithOracle.java
@DataJpaTest
@ActiveProfiles("test")
/*
By default @DataJpaTest uses embeded h2 database and ignores the connection string declared in application.properties.
This annotation disables this behavior and db configured in bootstrap.yml will be used by @DataJpaTest test.
*/
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
@Sql("classpath:my_data.sql")
class MyRepositoryTest {
}
View docker.jmx
docker run -d --restart=always
\
-p {{service_port}}:8080

-p {{jmx_port}}:{{jmx_port}}
\
-e JAVA_OPTS='
    -Xmx{{java_memory_limit}}
   -XX:+UseConcMarkSweepGC
    -XX:NativeMemoryTracking=summary
View docker.jmx.v2
docker run --rm -it -p 8080:8080 -p 9010:9010 -e JAVA_TOOL_OPTIONS='
-Xmx450M
-XX:+UseConcMarkSweepGC
-XX:NativeMemoryTracking=summary
-Djava.rmi.server.hostname=127.0.0.1
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=9010
-Dcom.sun.management.jmxremote.rmi.port=9010
-Dcom.sun.management.jmxremote.local.only=false
-Dcom.sun.management.jmxremote.authenticate=false
View jpa_spring_log
spring:
jpa:
show-sql: true
properties.hibernate.format_sql: true
View hibernate_log
logging:
level:
org.hibernate.SQL: DEBUG
org.hibernate.type.descriptor.sql.BasicBinder: TRACE
View run
# Build to local docker
gradle build jibDockerBuild
# Run in local docker
docker run --rm -it -e SPRING_PROFILES_ACTIVE=local -p 8080:8080 IMAGE
# Build to TAR using arbitrary image
gradle build jibBuildTar -Djib.from.image=openjdk:11-jre --exclude-task test