Skip to content

Instantly share code, notes, and snippets.

@John-Chan
John-Chan / HOWTO.md
Created May 23, 2024 02:35 — forked from Toparvion/HOWTO.md
JUnit test for conditional Spring Boot bean registration (@ConditionalOnProperty)

Problem

Suppose you have two classes that should be registered with Spring context exclusively, e.g. only one of the beans must exist in the context at any time based on some boolean property value. Of course you can do it by adding explicit if condition into your @Configuration class. But if the classes have no common interface it may be quite cumbersome. As an alternative you can use @ConditionalOnProperty annotation on your classes, e.g.:

@Service
@ConditionalOnProperty(name = "use-left-service", havingValue = "true", matchIfMissing = false)
public class LeftService
@John-Chan
John-Chan / ComPort over Network.md
Created March 20, 2022 12:22 — forked from DraTeots/ComPort over Network.md
ComPort over Network
@John-Chan
John-Chan / p3c-pmd.pom.xml
Created November 9, 2020 06:26 — forked from yangl/p3c-pmd.pom.xml
阿里巴巴Java代码规约扫描插件 p3c-pmd使用例子 https://github.com/alibaba/p3c/tree/master/p3c-pmd
<build>
<plugins>
<!-- ... -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.8</version>
<configuration>
<rulesets>
<ruleset>/rulesets/java/ali-comment.xml</ruleset>
# Simple SonarQube database and user creation for Postgresql
#
sudo -u postgres psql postgres
CREATE DATABASE sonar;
CREATE USER sonar WITH PASSWORD 'verysecret';
GRANT ALL PRIVILEGES ON DATABASE sonar TO sonar;
CREATE SCHEMA schema_sona AUTHORIZATION sonar;
ALTER USER sonar SET search_path to schema_sona;
git rm -r --cached .
git add .
git commit -m ".gitignore is now working"
@John-Chan
John-Chan / git-multiple-pullandpush.txt
Created October 17, 2017 02:59 — forked from zokeber/git-multiple-pullandpush.txt
Git pull/push from multiple remote locations
Step 1 - Add repositories primary server:
touch README.md
git init
git add README.md
git commit -m "Initial commit"
git remote add origin git@remote-server1:repositories1/app
git push -u origin master
Step 2 - Add repositories alternative server:
git remote add alter git@remote-server2:repositories2/app
@John-Chan
John-Chan / install_vmware_tools.sh
Created August 25, 2017 14:23 — forked from wangyuhere/install_vmware_tools.sh
sh: Install VMWare Tools Ubuntu Server
#Change to super user
sudo su
#Update your sources
apt-get update
#Upgrade your installed packages and force kernel upgrade
apt-get dist-upgrade
###
//
// Base32.swift
// Created by Steve Streza on 26.9.14.
// Updated by Martin Troup on 4.11.16.
//
import Foundation
func Base32Encode(data: Data) -> String {
let alphabet = [ "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "2", "3", "4", "5", "6", "7"]
return Base32Encode(data: data, alphabet: alphabet)
@John-Chan
John-Chan / gist:f67ecb428d431ff9e1f39a1c7031fbed
Created December 26, 2016 05:54 — forked from michail-nikolaev/gist:3840973
JPA - Tree structure with automatic order and tested operations for it
@Entity
public class TreeCategory extends IdentifiableEntity {
....
@ManyToOne(optional = true)
@JoinColumn(name = "parent_id", referencedColumnName = "id")
public TreeCategory getParent() {
return parent;
}
<bean id="authenticationManager" class="org.jasig.cas.authentication.PolicyBasedAuthenticationManager">
<constructor-arg>
<map>
<entry key-ref="proxyAuthenticationHandler" value-ref="proxyPrincipalResolver" />
<entry key-ref="primaryAuthenticationHandler" value-ref="primaryPrincipalResolver" />
<entry key-ref="ldapAuthenticationHandler" value-ref="usernamePasswordCredentialsResolver" />
</map>
</constructor-arg>