Skip to content

Instantly share code, notes, and snippets.

View magicliang's full-sized avatar

Magicliang magicliang

  • Currently Beijing.
View GitHub Profile
@magicliang
magicliang / 如何让字符串能够被反序列化.java
Created August 31, 2021 15:40
如何让字符串能够被反序列化
/**
* 解 json 双引号引用
* @param originString 原始字符串
* @return 真 json 字符串
*/
private static String deEscapeJsonQuote(String originString) {
final String tempStr = originString.replaceAll("\"\"", "\"");
return tempStr.substring(1, tempStr.length() - 1);
}
@magicliang
magicliang / 线程池销毁的例子 1.java
Created January 8, 2020 10:40
依赖于 spring 钩子
/**
* 在一个 bean 被销毁以前对它应用本处理器
* Apply this BeanPostProcessor to the given bean instance before its
* destruction, e.g. invoking custom destruction callbacks.
* <p>Like DisposableBean's {@code destroy} and a custom destroy method, this
* callback will only apply to beans which the container fully manages the
* lifecycle for. This is usually the case for singletons and scoped beans.
*
* @param bean the bean instance to be destroyed
* @param beanName the name of the bean
@magicliang
magicliang / howToParseXMLBeanDefinitions.java
Created January 7, 2020 07:22
spring的DefaultBeanDefinitionDocumentReader解析xml得到资源的解法
/**
* Parse the elements at the root level in the document:
* "import", "alias", "bean".
* @param root the DOM root element of the document
*/
protected void parseBeanDefinitions(Element root, BeanDefinitionParserDelegate delegate) {
if (delegate.isDefaultNamespace(root)) {
NodeList nl = root.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
Node node = nl.item(i);
@magicliang
magicliang / instance-threadlocal.java
Last active January 7, 2020 06:35
一段 spring context 的 threadlocal 的用法
private final ThreadLocal<TestContext> testContextHolder = ThreadLocal.withInitial(
// Implemented as an anonymous inner class instead of a lambda expression due to a bug
// in Eclipse IDE: "The blank final field testContext may not have been initialized"
new Supplier<TestContext>() {
@Override
public TestContext get() {
return copyTestContext(TestContextManager.this.testContext);
}
});
# 地区
locale
# 校验时区
date -R