Skip to content

Instantly share code, notes, and snippets.

View gilbertolptn's full-sized avatar

Gilberto Lptn gilbertolptn

  • Rio Grande do Sul
View GitHub Profile
# 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
logging:
level:
org.hibernate.SQL: DEBUG
org.hibernate.type.descriptor.sql.BasicBinder: TRACE
spring:
jpa:
show-sql: true
properties.hibernate.format_sql: true
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
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
SCRIPT TO 'db-dump.sql'
@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 {
}
@gilbertolptn
gilbertolptn / CustomErrorAttibutes.java
Created May 19, 2021 12:11
This classs replace default error attributes globaly on Spring MVC applications
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
@gilbertolptn
gilbertolptn / application.properties
Created November 4, 2021 19:22
Configurações de Tomcat para o Spring
server.error.include-stacktrace=never # when to include a stacktrace attribute (never/alway/on-trace-param)
spring.kafka.consumer.auto-offset-reset=earliest
spring.kafka.consumer.enable-auto-commit=true
spring.kafka.consumer.max-poll-records=100
spring.kafka.consumer.fetch-max-wait=2s
spring.kafka.listener.type=BATCH
spring.kafka.listener.concurrency=12
spring.kafka.consumer.group-id=batchTest1
spring.kafka.client-id=batchTest1
spring.kafka.listener.ack-mode=BATCH