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 / ClashVergRevProfile.js
Created January 22, 2024 08:25
Clash-Verg-Rev Profiles Enhanced Mode 增强模式脚本
// This script used to enhance clash rules
// rules maintained by yourself
const local_rules = [
"DOMAIN-SUFFIX,example.local,DIRECT,no-resolve"
];
// copy from https://github.com/Loyalsoldier/clash-rules
const extra_rules = [
@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>
@John-Chan
John-Chan / settings.xml
Created August 12, 2020 12:58
maven global profile to setup aliyun repo
<profiles>
<profile>
<id>maven-aliyun</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<pluginRepositories>
<pluginRepository>
<id>aliyun-plugin</id>
@John-Chan
John-Chan / CorsConfig.java
Last active July 6, 2019 04:30
spring cloud gateway cors config
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;
/**
* Cors Config
@John-Chan
John-Chan / TaskSyncDialog.java
Last active May 15, 2019 15:51
JavaFX dialog to sync with anync Task
package me.jclazz.jfx.gui.component;
import javafx.application.Platform;
import javafx.concurrent.Task;
import javafx.concurrent.Worker;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Dialog;
import javafx.scene.control.ProgressBar;
# 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;
@John-Chan
John-Chan / ora_debug_msg.sql
Created June 14, 2018 00:54
write debug message to file in oracle
-- output debug message
-- create or replace directory "dbg_log_dir" as 'c:\zfmm_db_log';
-- grant read on directory "dbg_log_dir" to zfmm;
-- grant write on directory "dbg_log_dir" to zfmm;
-- call zfmm.DEBUG_MSG('12345678');
CREATE OR REPLACE PROCEDURE DEBUG_MSG(MSG VARCHAR2) IS
OUTPUTFILE UTL_FILE.FILE_TYPE;
BEGIN
OUTPUTFILE := UTL_FILE.FOPEN('dbg_log_dir', 'zfmm.log', 'a');
UTL_FILE.PUTF(OUTPUTFILE, '[%s] %s\n', TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS'), MSG);
git rm -r --cached .
git add .
git commit -m ".gitignore is now working"