一个轻量级的 Java 注解处理器,可从配置文件 (YAML/Properties) 生成类型安全的 Java 代码
Propify is a Java annotation processor that generates typed APIs from configuration files (YAML, INI, .properties), i18n bundles, and schema definitions (JSON Schema, OpenAPI).
If a config key, message key, or schema shape changes, the generated API changes with it and mismatches show up during compilation rather than as runtime lookups.
It supports nested properties, custom lookup providers (env/system/custom), ICU4J message formatting, and schema-based POJO generation. Generated code is regular Java; you call it from your application code.
config.get("a.b.c")-style lookups..properties.Add dependency and annotation processor:
com.vgerbot
propify
3.0.0
maven-compiler-plugin
3.8.1
1.8
1.8
com.vgerbot
propify
3.0.0
dependencies {
implementation 'com.vgerbot:propify:3.0.0'
annotationProcessor 'com.vgerbot:propify:3.0.0'
}propify as an annotation processor.Create src/main/resources/application.yml:
server:
host: localhost
port: 8080
database:
url: jdbc:mysql://localhost:3306/mydb
username: root
password: secretAnnotate an interface:
@Propify(location = "application.yml")
public interface AppConfig {}Use the generated API:
public class Main {
public static void main(String[] args) {
AppConfigPropify cfg = AppConfigPropify.getInstance();
System.out.println(cfg.getServer().getHost());
System.out.println(cfg.getDatabase().getUrl());
}
}Full @Propify Documentation - Learn about custom lookups, media types, advanced configuration options, and more.
Generate type-safe resource bundles using ICU4J:
Create message files in resources/:
# messages.properties (default)
welcome=Welcome
greeting=Hello, {0}!
# messages_zh_CN.properties
welcome=欢迎
greeting=你好, {0}!Annotate a class:
@I18n(baseName = "messages", defaultLocale = "en")
public class Messages {}Access messages:
String hi = MessageResource.getDefault().greeting("Alice");
String hiZh = MessageResource.get(Locale.CHINESE).greeting("张三");Full @I18n Documentation - Explore ICU MessageFormat, pluralization, date/time formatting, and multi-locale support.
Generate mutable POJO/DTO classes from schema definitions for REST APIs and data modeling:
// 1. Create a JSON Schema or OpenAPI spec
@SchemaGen(location = "schemas/user.schema.json")
public interface UserSchema {}
// 2. Use the generated POJO
User user = User.builder()
.username("johndoe")
.email("[email protected]")
.build();
// 3. Serialize/deserialize with Jackson
ObjectMapper mapper = new ObjectMapper();
String json = mapper.writeValueAsString(user);
User deserializedUser = mapper.readValue(json, User.class);Key points:
@NotNull, @Email, @Size, etc.)Full @SchemaGen Documentation - Learn about OpenAPI support, type mapping, validation annotations, and more.
@Propify, @I18n, and @SchemaGen annotationsCheck the example/ directory for complete working examples:
If you encounter any issues or have questions about using Propify:
git checkout -b feature/xyz)Please follow the existing coding style and update tests.
MIT © 2024 vgerbot-libraries
暂无开放 Issues,或尚未同步最近议题。