Spring中XML与JavaBean相互转换

private static final ObjectMapper objectMapper = new XmlMapper(); public static <T> T xmlToObj(final String data, Class<T> clazz) { try { return objectMapper.readValue(data, clazz); } catch (Exception e) { log.error("{}", data); log.error(e.getMessage(), e); } return null; } public static String objToXML(final Object object) { try { return objectMapper.writeValueAsString(object); } catch (JsonProcessingException e) { log.error(e.getMessage(), e); } return ""; } //这个虽然是写着 JsonIgnoreProperties , 但

[翻译]calibre中的recipes的API文档

原文 class calibre.web.feeds.news.BasicNewsRecipe(options, log, progress_reporter)[source] 包含所有 recipe 所需逻辑的基类. 通过逐步覆盖此类中的更多功能, 你可以逐步实现更多自定义/强大的 recipe . 有关创建 recipe 的教程, 可参考 添加你喜欢的

Java中的文件锁

假设这情况情况, 同一台服务器上有个服务有两个进程(一般用作负载均衡, 以及在更新时切换使用). 有个定时任务, 但只需要其中之一执行就可以了. 添加

Python数据可视化demo

要安装好以下依赖 pyecharts + panda + sqlite3 import sqlite3 import pandas as pd from pyecharts import Line with sqlite3.connect('csi_indices.db') as con: # read_sql_query和read_sql都能通过SQL语句从数据库文件中获取数

为100亿内的数字建立md5彩虹表的数据仓库

思路 创建多张表, 规则如下(节省存储) 取 md5 的前2位作为后缀, 创建表名为 uid_${md5前2位字符} . 表结构如下 CREATE TABLE uid_xx ( uid UInt64, md5hash String ) ENGINE = MergeTree PARTITION BY substring(md5hash,

Java中读取ClassPath中的资源

假设有个代码目录结构为 java ├── hello │ └── world │ ├── Test.java │ └── hello.txt └── hello1.txt 则可以这样子读取 hello.txt 和 hello1.txt 的资源 class 方式 package hello.world; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.stream.Collectors; public class Test { public static

<Java 9模块化开发>读书笔记

模块描述符 module-info.java module your.module.name { //表示依赖某个模块. 即没有传递性的依赖. requires other.module.name; //表示依赖某个模块. 具有传递性的依赖 requires transitive other.module.name; //从当前模块中导出某些包, 以提

SpringBoot自定义starter

pom.xml <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.3.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-autoconfigure</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.25</version> </dependency> <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> </dependency> <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>${guava.version}</version> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> </dependency> </dependencies> <distributionManagement> <repository> <id>uniweibo</id> <name>uniweibo</name> <url>http://10.0.0.40:8081/repository/uniweibo/</url> </repository> </distributionManagement> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build> 上面的,

ThreadPoolExecutor中的异常捕获

现象 线上服务日志发现有中断(即日志前面有打印, 但后面的日志没打印), 并且又没有异常信息输出. 原因 代码示例 private static final ThreadPoolTaskExecutor THREAD_POOL_TASK_EXECUTOR = new ThreadPoolTaskExecutor(); static { THREAD_POOL_TASK_EXECUTOR.setQueueCapacity(10000); THREAD_POOL_TASK_EXECUTOR.setDaemon(true); THREAD_POOL_TASK_EXECUTOR.setThreadNamePrefix("global-%d"); THREAD_POOL_TASK_EXECUTOR.setRejectedExecutionHandler((r, executor) -> { L

SpringBoot结合InfluxDB收集监控统计信息

pom.xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <!-- 统计信息输出到 influxdb --> <dependency> <groupId>io.micrometer</groupId> <artifactId>micrometer-registry-influx</artifactId> </dependency> application.properties #### Spring Boot 监控 management.metrics.export.influx.enabled=true management.metrics.export.influx.auto-create-db=true management.metrics.export.influx.db=app_met

SpringBoot结合MyBatis配置多数据源

application.properties # mysql spring.datasource.jdbc-url=@config.jdbc.url@ spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.username=@config.jdbc.username@ spring.datasource.password=@config.jdbc.password@ # clickhouse ## clickhouse spring.clickhouse.jdbc-url=@config.clickhouse.url@ spring.clickhouse.driver-class-name=ru.yandex.clickhouse.ClickHouseDriver spring.clickhouse.username= spring.clickhouse.password= Java 代码配置 主 datasource package com.uniweibo.config; import org.apache.ibatis.session.SqlSessionFactory; import org.mybatis.spring.SqlSessionFactoryBean; import org.mybatis.spring.annotation.MapperScan; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.jdbc.DataSourceBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; import org.springframework.core.io.ClassPathResource; import javax.sql.DataSource; @Configuration @MapperScan(basePackages = {"com.uniweibo.dao.mapper", "com.uniweibo.meitu.dao.mapper", "com.uniweibo.xiaomi.dao.mapper"}, sqlSessionFactoryRef = "sqlSessionFactory" ) public class AppDataSourceConfig { /** 配置文件名, 放在 classpath

从传统SpringMVC迁移到SpringBoot

本文的迁移背景是: JDK7 + SpringMVC + 传统的 web.xml + 外部Tomcat 迁移到 JDK8 + SpringBoot2 + 嵌入式的Tomcat pom 注意事项 <build> <resources> <resource> <directory>src/main/resources</directory> <includes> <include>**/*.*</include> <!--<include>**/*.json</include>--> <!--<include>**/*.properties</include>--> </includes> <filtering>true</filtering> </resource> <resource> <directory>src/main/java</directory> <includes> <include>**/*.*</include> </includes> </resource> </resources> </build> 改造 web.xml

Java Metrics+Grafana+InfluxDB搭建监控系统

以下的测试, 都是基于 Ubuntu 14.04.2 LTS + Java 8 + SpringBoot Grafana 安装 sudo echo "deb https://packagecloud.io/grafana/stable/debian/ stretch main" > /etc/apt/sources.list.d/grafana.list curl https://packagecloud.io/gpg.key | sudo apt-key add - sudo apt-get update -y ; sudo apt-get install grafana 启动/停止 sudo service grafana-server start sudo service grafana-server stop 登录: http://127.0.0.1:3000 默认的用户名和密

ClickHouse入门记录

安装 我写了个脚本放在 gist 可以执行以下命令来自动安装: curl -L https://gist.githubusercontent.com/emacsist/ebb98839c814cdb2f16e20efcef9474e/raw/aa8e035ad2e61fa74f4c904a7953806c62155fa3/install-clickhouse.sh | bash 下面是脚本的完整内容: #!/usr/bin/env bash grep -q sse4_2 /proc/cpuinfo && echo "SSE 4.2 supported" || echo "SSE 4.2 not supported" grep -q sse4_2 /proc/cpuinfo || exit 1 sudo echo "deb http://repo.yandex.ru/clickhouse/deb/stable/ main/"

Netty与epoll资料收集

为什么 Netty 支持 native epoll ? stackoverflow.com Netty 的 epoll transport 使用 epoll edge-triggered , 而 java 的 NIO 库珍的是 level-triggered. 除此之外, epoll transport 暴露了一些在 Java NIO 中没出现的配置项, 例如: TCP_CORK, SO_REUSEPORT 等等. 什么是 edge-triggered 和 level-triggered? stackexchange 我没有