spring boot 读取配置文件yml

1
2
3
@Component
@ConfigurationProperties(prefix = "api")
@PropertySource(value = { "classpath:api.yml" })<br><br><br>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package com.foen.api.config;
 
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
 
/**
 * 读取代码生成相关配置
 *  get static,
 *  set @Value(“${}”)
 *
 * @author foen
 */
@Component
@ConfigurationProperties(prefix = "api")
@PropertySource(value = { "classpath:api.yml" })
public class ApiConfig
{
    /** 作者 */
    public static String author;
 
    /** 生成包路径 */
    public static String packageName;
 
    /** 自动去除表前缀,默认是false */
    public static boolean autoRemovePre;
 
    /** 表前缀(类名不会包含表前缀) */
    public static String tablePrefix;
    /** 表前缀(类名不会包含表前缀) */
    public static String testUrl;
    /** 表前缀(类名不会包含表前缀) */
    public static String proUrl;
 
    public static String getAuthor()
    {
        return author;
    }
 
    @Value("${author}")
    public void setAuthor(String author)
    {
        ApiConfig.author = author;
    }
 
    public static String getPackageName()
    {
        return packageName;
    }
 
    @Value("${packageName}")
    public void setPackageName(String packageName)
    {
        ApiConfig.packageName = packageName;
    }
 
    public static boolean getAutoRemovePre()
    {
        return autoRemovePre;
    }
 
    @Value("${autoRemovePre}")
    public void setAutoRemovePre(boolean autoRemovePre)
    {
        ApiConfig.autoRemovePre = autoRemovePre;
    }
 
    public static String getTablePrefix()
    {
        return tablePrefix;
    }
 
    @Value("${tablePrefix}")
    public void setTablePrefix(String tablePrefix)
    {
        ApiConfig.tablePrefix = tablePrefix;
    }
 
    public static String getTestUrl() {
        return testUrl;
    }
    @Value("${testUrl}")
    public void setTestUrl(String testUrl) {
        ApiConfig.testUrl = testUrl;
    }
 
    public static String getProUrl() {
        return proUrl;
    }
    @Value("${proUrl}")
    public void setProUrl(String proUrl) {
        ApiConfig.proUrl = proUrl;
    }
}

  

posted @   A汉克先生  阅读(226)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
点击右上角即可分享
微信分享提示