Keycloak in Spring Boot

🔐 Spring Security + Keycloak Flow Schema [Client Request] │ │ GET /admin/dashboard ▼ ┌─────────────────────────────┐ │ Spring Security Filter Chain│ │ ────────────────────────── │ │ Filters: │ │ - OAuth2LoginAuthentication │ │ - BearerTokenAuthentication │ │ - SecurityContextPersistence │ └─────────────────────────────┘ │ │ No authentication? ▼ ┌─────────────────────────────┐ │ Redirect to Keycloak Login │ │ (Authorization Endpoint)…

0 Comments

Wiremock in Spring Boot

1. Add dependencies In your pom.xml (for Maven) include: <dependencies> <!-- Spring Boot Starter Test --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <!-- WireMock for mocking HTTP services --> <dependency> <groupId>com.github.tomakehurst</groupId> <artifactId>wiremock-jre8</artifactId> <version>2.35.0</version> <scope>test</scope> </dependency> <!-- Optional: RestTemplate if using it for HTTP calls --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> <dependencies> <!-- Spring Boot Starter…

0 Comments

Basic Authentification in Spring Boot

1️⃣ Project Structure spring-security-demo/ ├── lib/ # Put all Spring Boot JARs here ├── src/ │ └── main/ │ └── java/ │ └── com/example/demo/ │ ├── DemoApplication.java │ ├── SecurityConfig.java │ ├── UserController.java │ └── CustomUserDetailsService.java spring-security-demo/ ├── lib/ # Put all Spring Boot JARs here ├── src/ │ └── main/ │ └── java/…

0 Comments

Caffeine in Spring Boot

Caffeine is a high-performance, near-optimal caching library for Java that integrates very well with Spring Boot. It provides features like size-based eviction, time-based expiration, refresh, and statistics. Here’s a step-by-step guide with example: 1. Add Dependencies In Maven: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-cache</artifactId> </dependency> <dependency> <groupId>com.github.ben-manes.caffeine</groupId> <artifactId>caffeine</artifactId> <version>3.1.8</version> <!-- use latest --> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-cache</artifactId>…

0 Comments

Elasticsearch in Spring Boot

1. Setup Maven Dependencies In your pom.xml: <dependencies> <!-- Spring Boot Web --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- Spring Data Elasticsearch --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-elasticsearch</artifactId> </dependency> <!-- Lombok (optional, for getters/setters) --> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> <!-- Spring Boot Test --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <dependencies> <!-- Spring Boot Web -->…

0 Comments

Hibernate in Spring Boot

🔑 Hibernate / JPA Annotations Cheat Sheet AnnotationPurpose@EntityMarks a class as a persistent entity (mapped to a table).@Table(name = "...")Customizes the table name.@IdMarks the primary key field.@GeneratedValue(strategy = ...)Specifies primary key generation strategy. Common for Postgres: GenerationType.IDENTITY or GenerationType.SEQUENCE.@ColumnCustomizes a column (name, nullable, length, unique, etc.).@ManyToOneDefines a many-to-one relationship (foreign key).@OneToManyDefines a one-to-many relationship…

0 Comments

Spring Data JPA

🚀 Common Spring Data JPA Annotations @Entity → Marks a class as a JPA entity (maps to a table). @Table → Specifies the table name in the database. @Id → Marks a field as the primary key. @GeneratedValue → Defines how the primary key is generated (IDENTITY, SEQUENCE, etc.). @Column → Customizes column mapping…

0 Comments

WebClient in Spring Boot

WebClient is the non-blocking, reactive HTTP client in Spring WebFlux, introduced as a replacement for RestTemplate (though RestTemplate is still supported for blocking I/O). 1. Add Dependency If you’re using Maven, add: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-webflux</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-webflux</artifactId> </dependency> For Gradle: implementation 'org.springframework.boot:spring-boot-starter-webflux' implementation 'org.springframework.boot:spring-boot-starter-webflux' 2. Create a WebClient Bean You can configure…

0 Comments

Liquibase with Spring Boot

1. What is Liquibase? Liquibase is a database version control tool. It allows you to manage schema changes (like creating tables, adding columns, indexes, etc.) across environments in a consistent way. With Spring Boot, it integrates seamlessly. 2. Add Dependencies In your pom.xml (Maven project): <dependencies> <!-- Spring Boot Starter Data JPA --> <dependency>…

0 Comments

Spring Boot Data MongoDB

📌 Common Spring Data MongoDB Annotations @DocumentMarks a class as a MongoDB document (like an @Entity in JPA).collection attribute can specify the collection name.@Document(collection = "users") public class User { ... } @IdMarks the primary identifier field (usually _id in MongoDB).@Id private String id; @FieldMaps a Java field to a specific MongoDB field name.@Field("user_name")…

0 Comments

End of content

No more pages to load