Skip to content

Instantly share code, notes, and snippets.

@j-tim
j-tim / application.properties
Created September 29, 2019 18:22
Enable JMX (Disabled by default since Spring Boot 2.2)
spring.jmx.enabled=true
@j-tim
j-tim / application.yml
Created September 29, 2019 18:24
Enable JMX (Disabled by default since Spring Boot 2.2)
spring:
jmx:
enabled: true
@j-tim
j-tim / LazyInitializedService.java
Created September 29, 2019 18:50
Service class annotation with @lazy (Since Spring Framework 5.2 and Spring Boot 2.2) to enable lazy bean initialization
package nl.jtim.spring.boot.lazy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
@Service
@Lazy
@j-tim
j-tim / NonLazyInitializedService.java
Created September 29, 2019 18:56
Service class annotated with @lazy(value = false) (Since Spring Framework 5.2 and Spring Boot 2.2) to disable lazy bean initialization
package nl.jtim.spring.boot.lazy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
@Service
@Lazy(value = false)
@j-tim
j-tim / pom.xml
Last active October 4, 2019 09:07
Maven Spring Boot 2.2 parent example
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
@j-tim
j-tim / MyVeryCoolService.java
Created October 11, 2019 11:20
Spring Boot 2.2 @ConditionalOnCloudPlatform Kubernetes detection
package nl.jtim.spring.boot;
import org.springframework.boot.autoconfigure.condition.ConditionalOnCloudPlatform;
import org.springframework.boot.cloud.CloudPlatform;
import org.springframework.stereotype.Service;
@Service
@ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES)
public class MyVeryCoolService {
}
@j-tim
j-tim / docker-compose.yml
Last active June 26, 2023 16:01
Elasticsearch 7.x Single Cluster Node for local development including Kibana
version: '3.7'
services:
# Elasticsearch Docker Images: https://www.docker.elastic.co/
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.4.0
container_name: elasticsearch
environment:
- xpack.security.enabled=false
@j-tim
j-tim / spring-boot-2.2-health-actuator-endpoint-response.json
Created October 17, 2019 12:41
Spring Boot 2.2 Health Actuator Response (Actuator V3)
{
"status": "UP",
"components": {
"db": {
"status": "UP",
"details": {
"database": "HSQL Database Engine",
"result": 1,
"validationQuery": "SELECT COUNT(*) FROM INFORMATION_SCHEMA.SYSTEM_USERS"
}
@j-tim
j-tim / pre-spring-boot-2.2-health-actuator-endpoint-response.json
Last active October 17, 2019 13:02
Pre Spring Boot 2.2 Health Actuator Response (Actuator V2)
{
"status": "UP",
"details": {
"db": {
"status": "UP",
"details": {
"database": "HSQL Database Engine",
"result": 1,
"validationQuery": "SELECT COUNT(*) FROM INFORMATION_SCHEMA.SYSTEM_USERS"
}
@j-tim
j-tim / ImmutableStockQuoteSubscriptionProperties.java
Last active October 18, 2019 11:57
Spring Boot 2.2 Immutable configuration binding class example
package com.example.immutable.configuration.binding;
import lombok.Getter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.ConstructorBinding;
@Getter
@ConfigurationProperties("stock.quote.subscription")
public class ImmutableStockQuoteSubscriptionProperties {