自留地

得之坦然,失之淡然


  • 首页

  • 标签

  • 分类

  • 归档

  • 追番

  • 站点地图

PF4J简单使用

发表于 2019-09-24 | 分类于 Learning
本文字数: 872 | 阅读时长 ≈ 4 分钟

plugin

PF4J是一个Java轻量级的插件框架,可以实现动态加载,执行,卸载外部插件(支持jar以及zip),具体可以看官网介绍。

本文例子基于Github地址:https://github.com/pf4j/pf4j

1
2
3
4
5
<dependency>
<groupId>org.pf4j</groupId>
<artifactId>pf4j</artifactId>
<version>3.0.1</version>
</dependency>
阅读全文 »

规约模式(Specification Pattern)

发表于 2019-06-24 | 分类于 Learning
本文字数: 1k | 阅读时长 ≈ 5 分钟

规约模式(Specification Pattern),简单来说就是就是约束条件,例如从数据库中获取到满足约束条件的数据(where条件之后即为约束条件):

1
select * from `book` where `name` like `%java%` and `price` < 50;

如果我们要用java实现类似约束,可能会想到:

1
2
3
4
5
for (Book book : books) {
if (book.name.contains("java") && book.price < 40) {
System.out.println(book);
}
}
阅读全文 »

Spring中的Properties

发表于 2019-05-23 | 分类于 Learning
本文字数: 2k | 阅读时长 ≈ 9 分钟

摘自Environment注释:

Properties play an important role in almost all applications, and may originate from a variety of sources: properties files, JVM system properties, system environment variables, JNDI, servlet context parameters, ad-hoc Properties objects, Maps, and so on. The role of the environment object with relation to properties is to provide the user with a convenient service interface for configuring property sources and resolving properties from them.

阅读全文 »

Spring中的Profiles

发表于 2019-05-20 | 分类于 Learning
本文字数: 850 | 阅读时长 ≈ 4 分钟

摘自Environment注释:

A profile is a named, logical group of bean definitions to be registered with the container only if the given profile is active. Beans may be assigned to a profile whether defined in XML or via annotations; see the spring-beans 3.1 schema or the @Profile annotation for syntax details. The role of the Environment object with relation to profiles is in determining which profiles (if any) are currently active, and which profiles (if any) should be active by default.

profiles类似Maven中的profiles,Spring允许配置多个profile,但只加载激活的profile,通过profiles配置,可以实现不同环境使用不同的配置(例如不同环境使用不同的数据库配置)

阅读全文 »

Spring中的Environment

发表于 2019-05-19 | 分类于 Learning
本文字数: 1.9k | 阅读时长 ≈ 9 分钟

Environment

Environment表示应用当前所运行的环境。

Interface representing the environment in which the current application is running. Models two key aspects of the application
environment: profiles and properties. Methods related to property access are exposed via the PropertyResolver superinterface.

A profile is a named, logical group of bean definitions to be registered with the container only if the given profile is active. Beans may be assigned to a profile whether defined in XML or via annotations; see the spring-beans 3.1 schema or the @Profile annotation for syntax details. The role of the Environment object with relation to profiles is in determining which profiles (if any) are currently active, and which profiles (if any) should be active by default.

Properties play an important role in almost all applications, and may originate from a variety of sources: properties files, JVM system properties, system environment variables, JNDI, servlet context parameters, ad-hoc Properties objects, Maps, and so on. The role of the environment object with relation to properties is to provide the user with a convenient service interface for configuring property sources and resolving properties from them

阅读全文 »

Spring中的PropertyResolver

发表于 2019-05-19 | 分类于 Learning
本文字数: 1.8k | 阅读时长 ≈ 9 分钟

PropertyResolver在Spring中的作用是负责属性解析,例如在XML中替换占位符(${})属性,@Value注解等

阅读全文 »

一致性哈希(Consistent Hashing)

发表于 2019-04-29 | 分类于 Learning
本文字数: 1.7k | 阅读时长 ≈ 7 分钟

一致性Hash算法

需求

在使用n台缓存服务器时,一种常见的负载均衡的做法是:对资源o的请求做hash(o) mod n,来决定映射的到的服务器。当需要增加或减少缓存服务器时,最糟糕的情况是,因为所有hash(o) mod n值被改变,导致所有缓存失效。

一致性哈希要求在服务器数量变化时,也尽量使同一个资源的请求,落在同一台服务器上。

阅读全文 »

学习SpringMVC国际化(二)

发表于 2019-03-08 | 分类于 Learning
本文字数: 1k | 阅读时长 ≈ 4 分钟

本文主要介绍springMVC中国际化的相关配置

MessageSource

示例:

1
2
3
4
5
6
7
8
@Bean
public ReloadableResourceBundleMessageSource messageSource() {
ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
messageSource.setBasenames("classpath:i18n/server");
messageSource.setDefaultEncoding("UTF-8");
messageSource.setFallbackToSystemLocale(false);
return messageSource;
}

SpringBean名称必须是messageSource

阅读全文 »

Java国际化简单介绍

发表于 2019-03-06 | 分类于 Learning
本文字数: 1.3k | 阅读时长 ≈ 6 分钟

本文主要介绍国际化中比较重要的类Locale,ResourceBundle,MessageFormat

java.util.Locale

Locale表示地区,在国际化中是一个非常重要的类。

基本方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import java.util.Locale;

public class LocaleTest {

public static void main(String[] args) {
Locale locale = Locale.getDefault();
System.out.println(locale); // zh_CN
System.out.println(locale.getCountry()); // CN
System.out.println(locale.getLanguage()); // zh
System.out.println(locale.getDisplayCountry()); // 中国
System.out.println(locale.getDisplayLanguage()); // 中文
}

}

可以看出Locale其实是由两部分组成,即{语言}_{地区}

阅读全文 »

学习SpringMVC国际化(一)

发表于 2019-03-03 | 分类于 Learning
本文字数: 1.2k | 阅读时长 ≈ 6 分钟

本文主要介绍如何使用springMVC实现国际化,项目使用jdk8+springMVC4.2.8+Velocity,全注解配置

阅读全文 »
1…345
辰伊

辰伊

一个空想主义者

42 日志
7 分类
67 标签
GitHub E-Mail
Links
  • Jenkov
  • DZone
0%
© 2019 — 2022 Yichen
由 Hexo 强力驱动
|
主题 — NexT.Gemini v5.1.4