{"id":562,"date":"2024-05-31T12:45:56","date_gmt":"2024-05-31T04:45:56","guid":{"rendered":"https:\/\/www.tqazy.com\/?p=562"},"modified":"2024-05-31T12:45:56","modified_gmt":"2024-05-31T04:45:56","slug":"configurationproperties","status":"publish","type":"post","link":"https:\/\/www.tqazy.com\/?p=562","title":{"rendered":"@ConfigurationProperties"},"content":{"rendered":"<h1>@ConfigurationProperties<\/h1>\n<h2>\u6982\u5ff5<\/h2>\n<p><code>@ConfigurationProperties<\/code> \u662fSpring\u6846\u67b6\u4e2d\u7684\u4e00\u4e2a\u6838\u5fc3\u6ce8\u89e3\u3002<\/p>\n<p>\u8fd9\u4e2a\u6ce8\u89e3\u4e3b\u8981\u7528\u4e8e\u5c06\u4e00\u7ec4\u76f8\u5173\u7684\u914d\u7f6e\u5c5e\u6027\u4ece\u914d\u7f6e\u6587\u4ef6\uff08\u5982 <code>application.properties<\/code> \u6216 <code>application.yml<\/code> \uff09\u96c6\u4e2d\u7ed1\u5b9a\u5230\u4e00\u4e2aJava\u5bf9\u8c61\u4e0a\uff0c\u4ece\u800c\u5b9e\u73b0\u914d\u7f6e\u7684\u7c7b\u578b\u5b89\u5168\u548c\u7ed3\u6784\u5316\u7ba1\u7406\u3002<\/p>\n<p>\u8fd9\u6837\u505a\u4e0d\u4ec5\u53ef\u4ee5\u51cf\u5c11\u786c\u7f16\u7801\uff0c\u8fd8\u80fd\u5229\u7528IDE\u7684\u4ee3\u7801\u8865\u5168\u548c\u7c7b\u578b\u68c0\u67e5\u529f\u80fd\uff0c\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u548c\u914d\u7f6e\u7684\u53ef\u7ef4\u62a4\u6027\u3002<\/p>\n<h2>\u901a\u4fd7\u8bf4\u6cd5<\/h2>\n<p>\u60f3\u8c61\u4e00\u4e0b\uff0c<code>@ConfigurationProperties<\/code> \u5c31\u50cf\u662f\u4e00\u4f4d\u7ec6\u5fc3\u7684\u7ba1\u5bb6\uff0c\u5b83\u4f1a\u4ece\u4f60\u5bb6\u7684\u201c\u914d\u7f6e\u4ed3\u5e93\u201d\uff08\u914d\u7f6e\u6587\u4ef6\uff09\u4e2d\uff0c\u6309\u7167\u4f60\u7559\u4e0b\u7684\u6e05\u5355\uff08\u914d\u7f6e\u5c5e\u6027\u7684\u524d\u7f00\uff09\uff0c\u6253\u5305\u597d\u6240\u6709\u4f60\u9700\u8981\u7684\u7269\u54c1\uff08\u914d\u7f6e\u503c\uff09\uff0c\u7136\u540e\u6574\u9f50\u5730\u6446\u653e\u5230\u4f60\u7684\u201c\u50a8\u7269\u95f4\u201d\uff08\u4e00\u4e2aJava\u7c7b\uff09\u91cc\u3002\u8fd9\u6837\uff0c\u4f60\u5c31\u53ef\u4ee5\u5728\u9700\u8981\u7684\u65f6\u5019\uff0c\u76f4\u63a5\u4ece\u50a8\u7269\u95f4\u91cc\u62ff\u51fa\u6574\u5957\u7269\u54c1\uff0c\u800c\u4e0d\u9700\u8981\u9010\u4e2a\u53bb\u4ed3\u5e93\u5bfb\u627e\uff0c\u65e2\u65b9\u4fbf\u53c8\u4e0d\u5bb9\u6613\u51fa\u9519\u3002<\/p>\n<h2>\u6240\u5c5e<\/h2>\n<blockquote>\n<p>import org.springframework.boot.context.properties.ConfigurationProperties;<\/p>\n<\/blockquote>\n<h2>\u4f5c\u7528<\/h2>\n<ul>\n<li><strong>\u96c6\u4e2d\u7ba1\u7406\u914d\u7f6e\uff1a<\/strong> \u5c06\u5206\u6563\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684\u76f8\u5173\u5c5e\u6027\u96c6\u4e2d\u5230\u4e00\u4e2aJava Bean\u4e2d\uff0c\u4fbf\u4e8e\u7ba1\u7406\u548c\u7ef4\u62a4\u3002<\/li>\n<li><strong>\u7c7b\u578b\u5b89\u5168\uff1a<\/strong> \u907f\u514d\u786c\u7f16\u7801\u548c\u5b57\u7b26\u4e32\u89e3\u6790\u9519\u8bef\uff0c\u63d0\u4f9b\u7f16\u8bd1\u65f6\u68c0\u67e5\u3002<\/li>\n<li><strong>\u7b80\u5316\u4ee3\u7801\uff1a<\/strong> \u51cf\u5c11\u91cd\u590d\u7684 <code>@Value<\/code> \u6ce8\u89e3\uff0c\u4f7f\u4ee3\u7801\u66f4\u52a0\u6e05\u6670\u548c\u6a21\u5757\u5316\u3002<\/li>\n<\/ul>\n<h2>\u7528\u6cd5<\/h2>\n<ul>\n<li><strong>\u5b9a\u4e49\u914d\u7f6e\u7c7b\uff1a<\/strong> \u521b\u5efa\u4e00\u4e2aJava\u7c7b\uff0c\u5e76\u4f7f\u7528 <code>@ConfigurationProperties<\/code> \u6ce8\u89e3\u6807\u8bb0\u3002\u901a\u5e38\u9700\u8981\u6307\u5b9a <code>prefix<\/code> \u5c5e\u6027\u6765\u6307\u660e\u914d\u7f6e\u6587\u4ef6\u4e2d\u5bf9\u5e94\u7684\u5c5e\u6027\u524d\u7f00\u3002<\/li>\n<li><strong>\u542f\u7528\u914d\u7f6e\u7ed1\u5b9a\uff1a<\/strong> \u5728Spring Boot\u5e94\u7528\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u5728\u914d\u7f6e\u7c7b\u4e0a\u52a0 <code>@EnableConfigurationProperties<\/code> \u6216\u5728\u4e3b\u7c7b\u4e0a\u52a0 <code>@SpringBootApplication<\/code> \u81ea\u52a8\u53d1\u73b0\u914d\u7f6e\u7c7b\uff0c\u4e5f\u53ef\u4ee5\u901a\u8fc7 <code>@Component<\/code> \u8ba9Spring\u626b\u63cf\u5230\u3002<\/li>\n<\/ul>\n<p>\u63a8\u8350\uff1a\u6700\u597d\u663e\u6027\u7684\u5728\u914d\u7f6e\u7c7b\u4e0a\u6dfb\u52a0<code>@EnableConfigurationProperties<\/code> \u6216\u8005 <code>@Component<\/code> \u6ce8\u89e3\uff0c\u8fd9\u6837\u65e2\u63d0\u9ad8\u914d\u7f6e\u7684\u53ef\u9884\u6d4b\u6027\u548c\u7a33\u5b9a\u6027\uff0c\u53c8\u660e\u786e\u8868\u660e\u7c7b\u7684\u4f5c\u7528\u548c\u610f\u56fe\uff0c\u63d0\u9ad8\u4e86\u4ee3\u7801\u53ef\u8bfb\u6027\u3002<\/p>\n<h2>\u4f7f\u7528\u573a\u666f<\/h2>\n<ul>\n<li><strong>\u6570\u636e\u5e93\u914d\u7f6e\uff1a<\/strong> \u7ba1\u7406\u6570\u636e\u5e93\u8fde\u63a5\u4fe1\u606f\uff0c\u5982URL\u3001\u7528\u6237\u540d\u3001\u5bc6\u7801\u7b49\u3002<\/li>\n<li><strong>\u670d\u52a1\u914d\u7f6e\uff1a<\/strong> \u5982\u90ae\u4ef6\u670d\u52a1\u3001\u7b2c\u4e09\u65b9API\u5bc6\u94a5\u7b49\u5916\u90e8\u670d\u52a1\u7684\u914d\u7f6e\u3002<\/li>\n<li><strong>\u81ea\u5b9a\u4e49\u7ec4\u4ef6\u914d\u7f6e\uff1a<\/strong> \u4e3a\u81ea\u5b9a\u4e49\u7684Spring\u7ec4\u4ef6\u63d0\u4f9b\u914d\u7f6e\u652f\u6301\u3002<\/li>\n<\/ul>\n<h2>\u4f7f\u7528\u793a\u4f8b<\/h2>\n<h3>\u793a\u4f8b1\uff1a\u6570\u636e\u5e93\u914d\u7f6e<\/h3>\n<p>application.yml<\/p>\n<pre><code class=\"language-yml\">spring:\n  datasource:\n    url: jdbc:mysql:\/\/localhost:3306\/mydb\n    username: root\n    password: secret<\/code><\/pre>\n<p>DataSourceConfig.java<\/p>\n<pre><code class=\"language-java\">import org.springframework.boot.context.properties.ConfigurationProperties;\nimport org.springframework.stereotype.Component;\n\n@Component\n@ConfigurationProperties(prefix = &quot;spring.datasource&quot;)\npublic class DataSourceConfig {\n    private String url;\n    private String username;\n    private String password;\n\n    \/\/ Getter and Setter methods...\n}<\/code><\/pre>\n<p>\u793a\u4f8b1\u4e2d\uff0c<code>prefix<\/code> \u5c5e\u6027\u503c <code>spring.datasource<\/code> \u610f\u5473\u7740\u914d\u7f6e\u6587\u4ef6\u4e2d\u4ee5 <code>spring.datasource.<\/code> \u5f00\u5934\u7684\u6240\u6709\u5c5e\u6027\u90fd\u5c06\u6620\u5c04\u5230\u8fd9\u4e2a\u7c7b\u7684\u76f8\u5e94\u5b57\u6bb5\u4e0a\u3002<\/p>\n<p>\u4f8b\u5982\uff0c<code>spring.datasource.url<\/code> \u5bf9\u5e94url\u5b57\u6bb5\uff0c<code>spring.datasource.username<\/code> \u5bf9\u5e94 <code>username<\/code> \u5b57\u6bb5\uff0c\u4f9d\u6b64\u7c7b\u63a8\u3002<\/p>\n<p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u5c06\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684\u76f8\u5173\u5c5e\u6027\u7ec4\u7ec7\u5728\u4e00\u8d77\uff0c\u5e76\u4ee5\u7c7b\u578b\u5b89\u5168\u7684\u65b9\u5f0f\u6ce8\u5165\u5230Java\u5bf9\u8c61\u4e2d\u3002<\/p>\n<h3>\u793a\u4f8b2\uff1a\u81ea\u5b9a\u4e49\u7ec4\u4ef6\u914d\u7f6e<\/h3>\n<p>\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u65e5\u5fd7\u670d\u52a1\u9700\u8981\u914d\u7f6e\u3002<\/p>\n<p>application.yml<\/p>\n<pre><code class=\"language-yml\">myapp.logging:\n  level: INFO\n  file-path: \/var\/log\/app.log<\/code><\/pre>\n<p>LoggingProperties.java<\/p>\n<pre><code class=\"language-java\">import org.springframework.boot.context.properties.ConfigurationProperties;\nimport org.springframework.stereotype.Component;\n\n@Component\n@ConfigurationProperties(prefix = &quot;myapp.logging&quot;)\npublic class LoggingProperties {\n    private String level;\n    private String filePath;\n\n    \/\/ Getter and Setter methods...\n}<\/code><\/pre>\n<p>\u6b64\u5904\u7684 <code>@ConfigurationProperties<\/code> \u7528\u6cd5\u7c7b\u4f3c\u4e8e\u793a\u4f8b1\u3002<\/p>\n<p>\u5728YAML\u914d\u7f6e\u6587\u4ef6\u4e2d\u4f7f\u7528 <code>file-path <\/code>\uff0c\u800c\u5728Java\u7c7b\u4e2d\u5b9a\u4e49\u4e3a <code>filePath<\/code> \uff0c\u4e24\u8005\u4e4b\u95f4\u80fd\u591f\u6210\u529f\u5bf9\u5e94\u5e76\u6ce8\u5165\uff0c\u662f\u56e0\u4e3aSpring\u5728\u5904\u7406\u5c5e\u6027\u540d\u79f0\u65f6\u662f\u4e0d\u533a\u5206\u5927\u5c0f\u5199\u7684\uff0c\u5e76\u4e14\u80fd\u591f\u81ea\u52a8\u9002\u5e94\u4e0d\u540c\u547d\u540d\u89c4\u8303\u7684\u6620\u5c04\u3002<\/p>\n<p>\u5177\u4f53\u6765\u8bf4\uff0cSpring Boot\u5728\u8fdb\u884c <code>@ConfigurationProperties<\/code> \u7ed1\u5b9a\u65f6\uff0c\u4f1a\u9075\u5faa\u4ee5\u4e0b\u89c4\u5219\uff1a<\/p>\n<ul>\n<li>\n<p><strong>\u9a7c\u5cf0\u5f0f\u5339\u914d\uff1a<\/strong> Spring Boot\u9ed8\u8ba4\u4f1a\u5c06\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684\u5c5e\u6027\u540d\uff08\u901a\u5e38\u662fkebab-case\uff0c\u5373\u77ed\u6a2a\u7ebf\u5206\u9694\u7684\u5355\u8bcd\uff0c\u5982 <code>file-path<\/code>\uff09\u8f6c\u6362\u4e3aJava\u9886\u57df\u7684\u9a7c\u5cf0\u547d\u540d\u6cd5\uff08camelCase\uff0c\u5982 <code>filePath<\/code> \uff09\uff0c\u8fd9\u4f7f\u5f97\u5c5e\u6027\u503c\u80fd\u591f\u5339\u914d\u5230Java\u7c7b\u4e2d\u7684\u5b57\u6bb5\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u5ffd\u7565\u5927\u5c0f\u5199\uff1a<\/strong> \u5728\u6620\u5c04\u8fc7\u7a0b\u4e2d\uff0cSpring\u662f\u4e0d\u654f\u611f\u5927\u5c0f\u5199\u7684\uff0c\u6240\u4ee5\u5373\u4f7fYAML\u6587\u4ef6\u4e2d\u7684\u5c5e\u6027\u540d\u5168\u90e8\u5c0f\u5199\uff0c\u53ea\u8981\u53bb\u6389\u77ed\u6a2a\u7ebf\u5e76\u76f8\u5e94\u8c03\u6574\u4e3a\u9a7c\u5cf0\u5f0f\uff0c\u5c31\u80fd\u5339\u914d\u5230Java\u7c7b\u4e2d\u7684\u76f8\u5e94\u5b57\u6bb5\u3002\u6bd4\u5982\uff1aYAML\u4e2d\u7684 <code>setting<\/code> \u53ef\u4ee5\u5bf9\u5e94java\u6587\u4ef6\u4e2d\u7684 <code>Setting<\/code> \u5b57\u6bb5\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u5bbd\u677e\u7ed1\u5b9a\uff1a<\/strong> Spring Boot\u63d0\u4f9b\u4e86\u4e00\u79cd\u5bbd\u677e\u7684\u7ed1\u5b9a\u7b56\u7565\uff0c\u8fd9\u610f\u5473\u7740\u5373\u4f7f\u914d\u7f6e\u5c5e\u6027\u540d\u79f0\u548cJava\u5b57\u6bb5\u540d\u79f0\u4e0d\u662f\u5b8c\u5168\u4e00\u81f4\uff0c\u53ea\u8981\u80fd\u901a\u8fc7\u4e0a\u8ff0\u89c4\u5219\u8f6c\u6362\u540e\u76f8\u5339\u914d\uff0c\u5c31\u80fd\u6210\u529f\u6ce8\u5165\u3002\u6bd4\u5982\uff1aYAML\u4e2d\u7684 <code>max-connections<\/code> \u53ef\u4ee5\u5bf9\u5e94java\u6587\u4ef6\u4e2d\u7684 <code>maxConnections<\/code> \u5b57\u6bb5\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u8fd9\u4e00\u8bbe\u8ba1\u63d0\u9ad8\u4e86\u914d\u7f6e\u7684\u7075\u6d3b\u6027\u548c\u6613\u7528\u6027\uff0c\u5f00\u53d1\u8005\u4e0d\u5fc5\u4e25\u683c\u9075\u5faa\u76f8\u540c\u7684\u547d\u540d\u89c4\u5219\u3002<\/p>\n<h2>\u6ce8\u610f<\/h2>\n<h3>\u6ce8\u610f1<\/h3>\n<p>\u8fd9\u4e2a\u5bbd\u677e\u7684\u6620\u5c04\u89c4\u5219\u5bf9\u4e8e <code>@Value<\/code> \u6ce8\u89e3\u662f\u4e0d\u9002\u7528\u7684\uff0c<code>@Value<\/code> \u8981\u6c42\u5c5e\u6027\u540d\u79f0\u4e0e\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684\u952e\u503c\u4e25\u683c\u5339\u914d\uff0c\u5305\u62ec\u5927\u5c0f\u5199\u548c\u5206\u9694\u7b26\u3002<\/p>\n<p>\u6bd4\u5982\u6b64\u5904\u5c31\u5e94\u8be5\u8fd9\u6837\u5bf9\u5e94\uff1a<\/p>\n<pre><code class=\"language-java\">@Value(&quot;${file-path}&quot;)\nprivate String filePath;<\/code><\/pre>\n<h3>\u6ce8\u610f2<\/h3>\n<p><code>@ConfigurationProperties<\/code> \u524d\u7f00\uff08<code>prefix<\/code>\uff09\u5339\u914d\u662f\u4e25\u683c\u7684\uff0c\u4e0d\u6d89\u53ca\u5927\u5c0f\u5199\u7684\u81ea\u52a8\u8f6c\u6362\u3002<\/p>\n<p>\u4f8b\u5982\uff1a\u5f53\u4f60\u5b9a\u4e49 <code>@ConfigurationProperties(prefix = &quot;my-config&quot;)<\/code> \u65f6\uff0c\u5373\u4f7fYAML\u914d\u7f6e\u6587\u4ef6\u4e2d\u4f7f\u7528\u4e86 <code>My_Config<\/code> \u4f5c\u4e3a\u524d\u7f00\uff0c\u6ca1\u6709\u5339\u914d\u5230\u5b9a\u4e49\u7684 <code>my-config<\/code> \u524d\u7f00\uff0c\u90a3\u4e48\u8be5\u914d\u7f6e\u7c7b\u5c06\u4e0d\u4f1a\u88ab\u6b63\u786e\u586b\u5145\u3002<\/p>\n<p>\u7b80\u800c\u8a00\u4e4b\uff0c\u5bbd\u677e\u6620\u5c04\u89c4\u5219\u4e3b\u8981\u5173\u6ce8\u4e8e\u5b57\u6bb5\u7ea7\u522b\u7684\u5c5e\u6027\u540d\u5339\u914d\uff0c\u800c\u4e0d\u662fprefix\u5c5e\u6027\u7684\u5339\u914d\u3002<code>prefix<\/code> \u9700\u8981\u76f4\u63a5\u4e14\u7cbe\u786e\u5730\u5339\u914d\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684\u524d\u7f00\u3002<\/p>\n<h2>@Value\u6ce8\u89e3 &amp; @ConfigurationProperties\u6ce8\u89e3<\/h2>\n<p><code>@Value<\/code> \u6ce8\u89e3\u548c <code>@ConfigurationProperties<\/code> \u6ce8\u89e3\u90fd\u662fSpring\u6846\u67b6\u63d0\u4f9b\u7684\u7528\u4e8e\u4ece\u914d\u7f6e\u6587\u4ef6\u4e2d\u8bfb\u53d6\u5c5e\u6027\u503c\u7684\u5de5\u5177\uff0c\u4f46\u5b83\u4eec\u5728\u4f7f\u7528\u65b9\u6cd5\u3001\u9002\u7528\u573a\u666f\u4e0a\u5404\u6709\u4fa7\u91cd\uff0c\u5f62\u6210\u4e86\u4e92\u8865\u5173\u7cfb\u3002<\/p>\n<h3>\u5173\u7cfb<\/h3>\n<p><strong>\u4e92\u8865\u6027\uff1a<\/strong> \u4e24\u8005\u90fd\u662f\u914d\u7f6e\u6ce8\u5165\u7684\u624b\u6bb5\uff0c\u4f46 <code>@Value<\/code> \u66f4\u9002\u7528\u4e8e\u7b80\u5355\u3001\u96f6\u6563\u7684\u914d\u7f6e\u6ce8\u5165\uff0c\u800c <code>@ConfigurationProperties<\/code> \u5219\u9002\u7528\u4e8e\u590d\u6742\u3001\u7ed3\u6784\u5316\u7684\u914d\u7f6e\u6570\u636e\u7ed1\u5b9a\u3002<br \/>\n<strong>\u529f\u80fd\u8986\u76d6\uff1a<\/strong> \u5728\u67d0\u79cd\u7a0b\u5ea6\u4e0a\uff0c<code>@ConfigurationProperties<\/code> \u7684\u529f\u80fd\u5305\u542b\u4e86 <code>@Value<\/code> \uff0c\u56e0\u4e3a\u5b83\u53ef\u4ee5\u5b8c\u6210\u5355\u4e2a\u503c\u7684\u6ce8\u5165\uff0c\u540c\u65f6\u4e5f\u80fd\u5904\u7406\u591a\u4e2a\u76f8\u5173\u8054\u7684\u914d\u7f6e\u5c5e\u6027\uff0c\u4f46\u53cd\u4e4b\u4e0d\u6210\u7acb\u3002<\/p>\n<h3>\u533a\u522b<\/h3>\n<p><strong>@Value<\/strong><\/p>\n<ul>\n<li><strong>\u7528\u6cd5\uff1a<\/strong> \u76f4\u63a5\u5728\u5b57\u6bb5\u6216\u65b9\u6cd5\u4e0a\u4f7f\u7528\uff0c\u901a\u8fc7 <code class=\"kb-btn\">${...}<\/code> \u5f15\u7528\u914d\u7f6e\u9879\u3002<\/li>\n<li><strong>\u7279\u70b9\uff1a<\/strong> \u9002\u5408\u7b80\u5355\u7684\u914d\u7f6e\u9879\u8bfb\u53d6\uff0c\u652f\u6301SpEL\u8868\u8fbe\u5f0f\uff0c\u7075\u6d3b\u6027\u9ad8\u4f46\u5bf9\u590d\u6742\u7ed3\u6784\u914d\u7f6e\u7ba1\u7406\u4e0d\u4fbf\u3002<\/li>\n<li><strong>\u573a\u666f\uff1a<\/strong> \u9002\u7528\u4e8e\u5c11\u91cf\u72ec\u7acb\u914d\u7f6e\u9879\u7684\u6ce8\u5165\uff0c\u6216\u8005\u9700\u8981\u5728\u8868\u8fbe\u5f0f\u4e2d\u52a8\u6001\u8ba1\u7b97\u7684\u573a\u5408\u3002<\/li>\n<li><strong>\u4f18\u70b9\uff1a<\/strong> \u7b80\u6d01\u5feb\u901f\uff0c\u65e0\u9700\u5b9a\u4e49\u989d\u5916\u7684\u7c7b\uff0c\u76f4\u63a5\u5728\u9700\u8981\u7684\u5730\u65b9\u4f7f\u7528\u3002<\/li>\n<li><strong>\u793a\u4f8b\uff1a<\/strong>\n<pre><code class=\"language-java\">@Value(\"${database.url}\") \nprivate String dbUrl;<\/code><\/pre>\n<\/li>\n<\/ul>\n<p><strong>@ConfigurationProperties<\/strong><\/p>\n<ul>\n<li><strong>\u7528\u6cd5\uff1a<\/strong> \u7c7b\u7ea7\u522b\u6ce8\u89e3\uff0c\u901a\u5e38\u8fd8\u9700\u914d\u5408 <code>@Component<\/code> \u6216\u901a\u8fc7 <code>@EnableConfigurationProperties<\/code> \u542f\u7528\uff0c\u4f7f\u7528 <code>prefix<\/code> \u6307\u5b9a\u914d\u7f6e\u524d\u7f00\u3002<\/li>\n<li><strong>\u7279\u70b9\uff1a<\/strong> \u9002\u7528\u4e8e\u7ed3\u6784\u5316\u7684\u914d\u7f6e\uff0c\u652f\u6301\u7c7b\u578b\u5b89\u5168\u7684\u7ed1\u5b9a\uff0c\u7b80\u5316\u5927\u91cf\u914d\u7f6e\u7ba1\u7406\uff0c\u81ea\u52a8\u5904\u7406\u96c6\u5408\u548c\u5d4c\u5957\u5c5e\u6027\uff0c\u4f46\u5bf9\u7b80\u5355\u914d\u7f6e\u663e\u5f97\u6709\u4e9b\u8fc7\u5ea6\u3002<\/li>\n<li><strong>\u573a\u666f\uff1a<\/strong> \u9002\u7528\u4e8e\u591a\u4e2a\u76f8\u4e92\u5173\u8054\u7684\u914d\u7f6e\u9879\uff0c\u7279\u522b\u662f\u5f53\u8fd9\u4e9b\u914d\u7f6e\u5f62\u6210\u4e00\u4e2a\u903b\u8f91\u4e0a\u7684\u6574\u4f53\u65f6\uff0c\u5982\u6570\u636e\u5e93\u3001\u90ae\u4ef6\u670d\u52a1\u5668\u7b49\u914d\u7f6e\u3002<\/li>\n<li><strong>\u4f18\u70b9\uff1a<\/strong> \u63d0\u4f9b\u7ed3\u6784\u5316\u914d\u7f6e\uff0c\u589e\u5f3a\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u53ef\u7ef4\u62a4\u6027\uff0c\u652f\u6301\u914d\u7f6e\u9a8c\u8bc1\u3002<\/li>\n<li><strong>\u793a\u4f8b\uff1a<\/strong> \u5728\u7c7b\u4e0a <code>@ConfigurationProperties(prefix = &quot;app.datasource&quot;)<\/code> \uff0c\u7c7b\u5185\u5b9a\u4e49\u76f8\u5e94\u5b57\u6bb5\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>@ConfigurationProperties \u6982\u5ff5 @ConfigurationProperties \u662fS [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[42],"tags":[43],"class_list":["post-562","post","type-post","status-publish","format-standard","hentry","category-42","tag-43"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>@ConfigurationProperties | \u9676\u5176\u7684\u4e2a\u4eba\u535a\u5ba2<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.tqazy.com\/?p=562\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"@ConfigurationProperties | \u9676\u5176\u7684\u4e2a\u4eba\u535a\u5ba2\" \/>\n<meta property=\"og:description\" content=\"@ConfigurationProperties \u6982\u5ff5 @ConfigurationProperties \u662fS [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.tqazy.com\/?p=562\" \/>\n<meta property=\"og:site_name\" content=\"\u9676\u5176\u7684\u4e2a\u4eba\u535a\u5ba2\" \/>\n<meta property=\"article:published_time\" content=\"2024-05-31T04:45:56+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2024\/05\/20240530090910445.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1080\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"\u9676\u5176\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u9676\u5176\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.tqazy.com\/?p=562#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.tqazy.com\/?p=562\"},\"author\":{\"name\":\"\u9676\u5176\",\"@id\":\"https:\/\/www.tqazy.com\/#\/schema\/person\/b2e89d56e70f15c261012417c5ef2c4e\"},\"headline\":\"@ConfigurationProperties\",\"datePublished\":\"2024-05-31T04:45:56+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.tqazy.com\/?p=562\"},\"wordCount\":62,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.tqazy.com\/#\/schema\/person\/b2e89d56e70f15c261012417c5ef2c4e\"},\"keywords\":[\"\u6ce8\u89e3\"],\"articleSection\":[\"\u6ce8\u89e3\"],\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.tqazy.com\/?p=562#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.tqazy.com\/?p=562\",\"url\":\"https:\/\/www.tqazy.com\/?p=562\",\"name\":\"@ConfigurationProperties | \u9676\u5176\u7684\u4e2a\u4eba\u535a\u5ba2\",\"isPartOf\":{\"@id\":\"https:\/\/www.tqazy.com\/#website\"},\"datePublished\":\"2024-05-31T04:45:56+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.tqazy.com\/?p=562#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.tqazy.com\/?p=562\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.tqazy.com\/?p=562#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.tqazy.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"@ConfigurationProperties\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.tqazy.com\/#website\",\"url\":\"https:\/\/www.tqazy.com\/\",\"name\":\"\u9676\u5176\u7684\u4e2a\u4eba\u535a\u5ba2\",\"description\":\"\u5f53\u4e0b\uff0c\u5373\u662f\u672a\u6765\",\"publisher\":{\"@id\":\"https:\/\/www.tqazy.com\/#\/schema\/person\/b2e89d56e70f15c261012417c5ef2c4e\"},\"alternateName\":\"TaoQi's Blog\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.tqazy.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"zh-Hans\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.tqazy.com\/#\/schema\/person\/b2e89d56e70f15c261012417c5ef2c4e\",\"name\":\"\u9676\u5176\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.tqazy.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2024\/06\/20240604021741672.jpg\",\"contentUrl\":\"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2024\/06\/20240604021741672.jpg\",\"width\":940,\"height\":940,\"caption\":\"\u9676\u5176\"},\"logo\":{\"@id\":\"https:\/\/www.tqazy.com\/#\/schema\/person\/image\/\"},\"description\":\"\u4e00\u4e2a\u5f88\u61d2\u7684\u7a0b\u5e8f\u5458\",\"sameAs\":[\"https:\/\/www.tqazy.com\"],\"url\":\"https:\/\/www.tqazy.com\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"@ConfigurationProperties | \u9676\u5176\u7684\u4e2a\u4eba\u535a\u5ba2","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.tqazy.com\/?p=562","og_locale":"zh_CN","og_type":"article","og_title":"@ConfigurationProperties | \u9676\u5176\u7684\u4e2a\u4eba\u535a\u5ba2","og_description":"@ConfigurationProperties \u6982\u5ff5 @ConfigurationProperties \u662fS [&hellip;]","og_url":"https:\/\/www.tqazy.com\/?p=562","og_site_name":"\u9676\u5176\u7684\u4e2a\u4eba\u535a\u5ba2","article_published_time":"2024-05-31T04:45:56+00:00","og_image":[{"width":1920,"height":1080,"url":"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2024\/05\/20240530090910445.jpg","type":"image\/jpeg"}],"author":"\u9676\u5176","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u9676\u5176","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"1 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.tqazy.com\/?p=562#article","isPartOf":{"@id":"https:\/\/www.tqazy.com\/?p=562"},"author":{"name":"\u9676\u5176","@id":"https:\/\/www.tqazy.com\/#\/schema\/person\/b2e89d56e70f15c261012417c5ef2c4e"},"headline":"@ConfigurationProperties","datePublished":"2024-05-31T04:45:56+00:00","mainEntityOfPage":{"@id":"https:\/\/www.tqazy.com\/?p=562"},"wordCount":62,"commentCount":0,"publisher":{"@id":"https:\/\/www.tqazy.com\/#\/schema\/person\/b2e89d56e70f15c261012417c5ef2c4e"},"keywords":["\u6ce8\u89e3"],"articleSection":["\u6ce8\u89e3"],"inLanguage":"zh-Hans","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.tqazy.com\/?p=562#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.tqazy.com\/?p=562","url":"https:\/\/www.tqazy.com\/?p=562","name":"@ConfigurationProperties | \u9676\u5176\u7684\u4e2a\u4eba\u535a\u5ba2","isPartOf":{"@id":"https:\/\/www.tqazy.com\/#website"},"datePublished":"2024-05-31T04:45:56+00:00","breadcrumb":{"@id":"https:\/\/www.tqazy.com\/?p=562#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.tqazy.com\/?p=562"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.tqazy.com\/?p=562#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.tqazy.com\/"},{"@type":"ListItem","position":2,"name":"@ConfigurationProperties"}]},{"@type":"WebSite","@id":"https:\/\/www.tqazy.com\/#website","url":"https:\/\/www.tqazy.com\/","name":"\u9676\u5176\u7684\u4e2a\u4eba\u535a\u5ba2","description":"\u5f53\u4e0b\uff0c\u5373\u662f\u672a\u6765","publisher":{"@id":"https:\/\/www.tqazy.com\/#\/schema\/person\/b2e89d56e70f15c261012417c5ef2c4e"},"alternateName":"TaoQi's Blog","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.tqazy.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"zh-Hans"},{"@type":["Person","Organization"],"@id":"https:\/\/www.tqazy.com\/#\/schema\/person\/b2e89d56e70f15c261012417c5ef2c4e","name":"\u9676\u5176","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.tqazy.com\/#\/schema\/person\/image\/","url":"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2024\/06\/20240604021741672.jpg","contentUrl":"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2024\/06\/20240604021741672.jpg","width":940,"height":940,"caption":"\u9676\u5176"},"logo":{"@id":"https:\/\/www.tqazy.com\/#\/schema\/person\/image\/"},"description":"\u4e00\u4e2a\u5f88\u61d2\u7684\u7a0b\u5e8f\u5458","sameAs":["https:\/\/www.tqazy.com"],"url":"https:\/\/www.tqazy.com\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/www.tqazy.com\/index.php?rest_route=\/wp\/v2\/posts\/562","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tqazy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tqazy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tqazy.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tqazy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=562"}],"version-history":[{"count":0,"href":"https:\/\/www.tqazy.com\/index.php?rest_route=\/wp\/v2\/posts\/562\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tqazy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=562"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tqazy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=562"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tqazy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=562"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}