从applcation.yml加载包含动态密钥的配置

时间:2018-07-09 17:25:01

标签: java spring spring-boot

我有一个[Mon Jul 9 20:21:19 2018] PHP Fatal error: Maximum execution time of 60 seconds exceeded in D:\Projects\shop\back-end\vendor\laravel\framework\src\Illuminate\Database\Query\Grammars\Grammar.php on line 85 [Mon Jul 9 20:21:19 2018] PHP Stack trace: [Mon Jul 9 20:21:19 2018] PHP 1. {main}() D:\Projects\shop\back-end\server.php:0 [Mon Jul 9 20:21:19 2018] PHP 2. require_once() D:\Projects\shop\back-end\server.php:21 [Mon Jul 9 20:21:19 2018] PHP 3. App\Http\Kernel->handle() D:\Projects\shop\back-end\public\index.php:55 [Mon Jul 9 20:21:19 2018] PHP 4. App\Http\Kernel->sendRequestThroughRouter() D:\Projects\shop\back-end\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php:116 ,如下所示

application.yml

我将spring: profiles: docker datasource: url: jdbc:postgresql://db/development username: postgres password: postgres ... app: notification: firebase: new-request: title: New request body: New request is pending cancel-request: title: Request canceled body: The user canceled the request email: new-request: title: New request body: New request is pending delete-friend: title: Lost friend body: You lost a friend ... 映射为

app

// ApplicationProperties.java @ConfigurationProperties(prefix = "app") public class ApplicationProperties { /** * The notification configuration */ @NestedConfigurationProperty private NotificationProperties notification; } // NotificationProperties.java public class NotificationProperties { /** * The notification configuration for Firebase */ @NestedConfigurationProperty private FirebaseProperties firebase; /** * The notification configuration for Email */ @NestedConfigurationProperty private EmailProperties email; } // FirebaseProperties.java public class FirebaseProperties { /** * Mapped properties for every title - body mapped notification */ private Map<String, TitleBodyProperties> properties = new HashMap<>(); public Map<String, TitleBodyProperties> getProperties() { return properties; } public void setProperties(Map<String, TitleBodyProperties> properties) { this.properties = properties; } } firebase中,我想使用配置的映射表示形式

email

此刻,我创建了要在地图中使用的对象,如下所示

firebase.get("new-request").getTitle()
firebase.get("new-request").getBody()

但是在这一点上,我无法将动态键映射到对象表示。

0 个答案:

没有答案