Skip to content

Instantly share code, notes, and snippets.

View mmafrar's full-sized avatar

Afrar Malakooth mmafrar

  • NextLabs
  • Kuala Lumpur, Malaysia
  • LinkedIn in/mmafrar
View GitHub Profile
@mmafrar
mmafrar / PrimaryDataSourceConfiguration.java
Created July 26, 2020 13:59
Configuring multiple data sources with Spring Boot 2 and Spring Data JPA
package com.example.demo;
import com.zaxxer.hikari.HikariDataSource;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
@mmafrar
mmafrar / SecondaryDataSourceConfiguration.java
Created July 26, 2020 13:59
Configuring multiple data sources with Spring Boot 2 and Spring Data JPA
package com.example.demo;
import com.zaxxer.hikari.HikariDataSource;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
@mmafrar
mmafrar / FileConfiguration.java
Created January 15, 2021 15:29
Integrating your Spring Boot project with Amazon S3
package com.example.demo;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@mmafrar
mmafrar / FileService.java
Created January 15, 2021 15:38
Integrating your Spring Boot project with Amazon S3
package com.example.demo;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.model.PutObjectRequest;
import com.amazonaws.services.s3.model.S3ObjectInputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@mmafrar
mmafrar / FileController.java
Created January 15, 2021 15:48
Integrating your Spring Boot project with Amazon S3
package com.example.demo;
import com.example.demo.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.CacheControl;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@mmafrar
mmafrar / FileControllerNew.java
Created March 24, 2021 15:46
Working with Amazon S3 presigned URLs in Spring Boot
package com.example.demo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@mmafrar
mmafrar / FileServiceNew.java
Created March 24, 2021 15:49
Working with Amazon S3 presigned URLs in Spring Boot
package com.example.demo;
import com.amazonaws.HttpMethod;
import com.amazonaws.services.s3.AmazonS3;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
@mmafrar
mmafrar / build.gradle
Created April 2, 2021 15:30
Implementing Spring Boot MVC CRUD operations with JPA and JSP
plugins {
id 'org.springframework.boot' version '2.4.4'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
@mmafrar
mmafrar / Contact.java
Created April 2, 2021 15:33
Implementing Spring Boot MVC CRUD operations with JPA and JSP
package com.example.demo.model;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@mmafrar
mmafrar / ContactRepository.java
Created April 2, 2021 15:35
Implementing Spring Boot MVC CRUD operations with JPA and JSP
package com.example.demo.repository;
import com.example.demo.model.Contact;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface ContactRepository extends JpaRepository<Contact, Integer> {
}