Skip to content

Instantly share code, notes, and snippets.

@PRASANTHRAJENDRAN
PRASANTHRAJENDRAN / AppSecurityConfig.java
Last active September 30, 2022 09:08
Cors issue after upgrading to use Spring Boot 2.4.0 -> java.lang.IllegalArgumentException: When allowCredentials is true, allowedOrigins cannot contain the special value "*"since that cannot be set on the "Access-Control-Allow-Origin" response header. To allow credentials to a set of origins, list them explicitly or consider using "allowedOrigin…
import org.springframework.context.annotation.Bean;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@gvenzl
gvenzl / TestDatabaseSetup.md
Last active May 24, 2023 08:54
Setup scripts for test databases for Oracle, MySQL, Postgres, SQL Server, and Db2
@jkuipers
jkuipers / HttpClientAutoConfiguration.java
Last active November 27, 2023 18:44
Spring Boot auto-configuration example for an Apache Components HTTP client and its usage in all RestTemplates created by the RestTemplateBuilder, plus trace logging support
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.CookieSpecs;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.client.RestTemplateCustomizer;
@jkuipers
jkuipers / LoggingClientHttpRequestInterceptor.java
Last active November 27, 2023 18:44
RestTemplate-interceptor that logs outgoing requests and resulting responses
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpRequest;
import org.springframework.http.MediaType;
import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.util.StreamUtils;
@thomasdarimont
thomasdarimont / App.java
Last active July 10, 2023 12:19
How to use custom SpEL functions in @value with Spring Boot
package demo;
import static java.lang.reflect.Modifier.*;
import java.util.Arrays;
import java.util.Set;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.BeanExpressionResolver;
@djspiewak
djspiewak / README.md
Last active August 29, 2015 14:16
Ivy REPL

Ivy REPL

Tired of spinning up SBT just to wire in some dependencies for a quick REPL session? Me too! The following pair of scripts completely resolves this issue. Well, mostly…

list-jars is not actually an Ivy2 resolver. What it does is enumerate all possible JARS within ~/.ivy2/cache (in other words, it excludes locally published artifacts), filters them where relevant for only Scala 2.11 cross-builds, and then orders them (via a very primitive partial ordering) by version, always selecting the latest one. No attempt is made to do any real dependency resolution and JAR hell escaping! So…if something doesn't work, you're on your own.

The fun thing is that you can just launch scala-ivy and use all your fancy third-party libraries without having to do any classpath setup.

Caveats

@mslinn
mslinn / installActivator.sh
Last active March 31, 2021 23:02
Installs Lightbend Activator on Ubuntu and Cygwin
#!/bin/bash
# From ScalaCourses.com Introduction to Play Framework with Scala course
# https://www.scalacourses.com/student/showLecture/158
set -eo pipefail
function help {
echo "Download or update Typesafe Activator on Linux and Cygwin"
echo "Usage: $(basename $0) [options]"
@dimitrisli
dimitrisli / Mail.scala
Last active March 22, 2017 08:51 — forked from mariussoutier/Mail.scala
Makes sense to wrap in Some instead of Option since the case is exhaustive
package object mail {
implicit def stringToSeq(single: String): Seq[String] = Seq(single)
implicit def liftToOption[T](t: T): Option[T] = Some(t)
sealed abstract class MailType
case object Plain extends MailType
case object Rich extends MailType
case object MultiPart extends MailType
@laurilehmijoki
laurilehmijoki / StaticFileServlet.scala
Last active December 12, 2018 04:59
Static file servlet with Scalatra
package coolcode
import java.io.File
import java.util.Properties
import org.scalatra.ScalatraServlet
class StaticFileServlet extends ScalatraServlet {
get("/*") {
val resourcePath = getResourcePath
@mariussoutier
mariussoutier / Mail.scala
Created August 23, 2012 12:13
Sending mails fluently in Scala
package object mail {
implicit def stringToSeq(single: String): Seq[String] = Seq(single)
implicit def liftToOption[T](t: T): Option[T] = Some(t)
sealed abstract class MailType
case object Plain extends MailType
case object Rich extends MailType
case object MultiPart extends MailType