﻿{"id":1542,"date":"2023-11-02T17:36:05","date_gmt":"2023-11-02T09:36:05","guid":{"rendered":"http:\/\/blog.sway.com.cn\/?p=1542"},"modified":"2023-11-02T17:52:00","modified_gmt":"2023-11-02T09:52:00","slug":"%e5%9c%a8windows%e4%b8%8b%e4%bd%bf%e7%94%a8jboss%e7%9a%84standalone%e6%a8%a1%e5%bc%8f%e8%bf%90%e8%a1%8c%e6%89%93%e6%88%90war%e5%8c%85%e7%9a%84srpingboot%e6%97%b6%e4%bd%bf%e7%94%a8%e5%a4%96%e9%83%a8","status":"publish","type":"post","link":"http:\/\/blog.sway.com.cn\/?p=1542","title":{"rendered":"\u5728Windows\u4e0b\u4f7f\u7528JBoss\u7684standalone\u6a21\u5f0f\u8fd0\u884c\u6253\u6210war\u5305\u7684SrpingBoot\u65f6\u4f7f\u7528\u5916\u90e8\u914d\u7f6e\u6587\u4ef6"},"content":{"rendered":"\n<p>\u5148\u5728SpringBoot\u9879\u76ee\u4e2d\u65b0\u589e\u4e00\u4e2aMyApplicationContext.java\u6587\u4ef6\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import org.springframework.context.ApplicationContextInitializer;\nimport org.springframework.context.ConfigurableApplicationContext;\nimport org.springframework.boot.env.YamlPropertySourceLoader;\nimport org.springframework.core.env.PropertySource;\nimport org.springframework.core.io.InputStreamResource;\n\nimport java.io.IOException;\nimport java.nio.file.Files;\nimport java.nio.file.Paths;\n\npublic class MyApplicationContextInitializer implements ApplicationContextInitializer&lt;ConfigurableApplicationContext> {\n\n    @Override\n    public void initialize(ConfigurableApplicationContext applicationContext) {\n        String activeProfile = applicationContext.getEnvironment().getProperty(\"spring.profiles.active\");\n        if(\"uat\".equals(activeProfile) || \"prod\".equals(activeProfile)){\n            YamlPropertySourceLoader loader = new YamlPropertySourceLoader();\n            try {\n                String jbossHome = (String) applicationContext.getEnvironment().getSystemEnvironment().get(\"JBOSS_HOME\");\n                PropertySource&lt;?> propertySource = loader.load(\"externalConfiguration\", new InputStreamResource(Files.newInputStream(Paths.get(jbossHome+\"\\\\standalone\\\\configuration\\\\application-druid.yml\")))).get(0);\n                applicationContext.getEnvironment().getPropertySources().addLast(propertySource);\n            } catch (IOException e) {\n                throw new RuntimeException(e);\n            }\n        }\n\n    }\n}<\/pre>\n\n\n\n<p>\u7136\u540e\u518dresources\u7684META-INF\u76ee\u5f55\u4e2d\u521b\u5efa\u4e00\u4e2aspring.factories\u6587\u4ef6\uff0c\u5185\u5bb9\u9700\u8981\u6307\u5411\u5230\u521a\u521a\u521b\u5efa\u7684MyApplicationContextInitializer\u7c7b\u6587\u4ef6\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2023\/11\/image-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"242\" src=\"http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2023\/11\/image-2-1024x242.png\" alt=\"\" class=\"wp-image-1547\" srcset=\"http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2023\/11\/image-2-1024x242.png 1024w, http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2023\/11\/image-2-300x71.png 300w, http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2023\/11\/image-2-768x181.png 768w, http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2023\/11\/image-2-1536x362.png 1536w, http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2023\/11\/image-2.png 1661w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>\u5728\u7cfb\u7edf\u4e2d\u65b0\u5efaJBOSS_HOME\u73af\u5883\u5e76\u6307\u5411JBOSS\u7684\u6839\u76ee\u5f55\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><a href=\"http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2023\/11\/image.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2023\/11\/image.png\" alt=\"\" class=\"wp-image-1543\" width=\"499\" height=\"484\" srcset=\"http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2023\/11\/image.png 810w, http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2023\/11\/image-300x291.png 300w, http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2023\/11\/image-768x745.png 768w\" sizes=\"auto, (max-width: 499px) 100vw, 499px\" \/><\/a><\/figure>\n\n\n\n<p>\u7136\u540e\u5728jboss\u7684standalone\\configuration\u76ee\u5f55\u4e2d\u653e\u7f6e\u5bf9\u5e94\u7684\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><a href=\"http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2023\/11\/image-1.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2023\/11\/image-1.png\" alt=\"\" class=\"wp-image-1544\" width=\"475\" height=\"312\" srcset=\"http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2023\/11\/image-1.png 645w, http:\/\/blog.sway.com.cn\/wp-content\/uploads\/2023\/11\/image-1-300x197.png 300w\" sizes=\"auto, (max-width: 475px) 100vw, 475px\" \/><\/a><\/figure>\n\n\n\n<p>\u7136\u540e\u542f\u7528jboss\u670d\u52a1\uff0c\u6b64\u65f6springboot\u7684war\u5e94\u7528\u4f1a\u4f18\u5148\u5230\u8fd9\u4e2aconfiguration\u76ee\u5f55\u4e2d\u5bfb\u627e\u5bf9\u5e94\u7684application\u914d\u7f6e\u6587\u4ef6\uff0c\u627e\u4e0d\u5230\u65f6\u4fbf\u4f1a\u4f7f\u7528war\u5305\u4e2d\u7684\u914d\u7f6e\u6587\u4ef6\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5148\u5728SpringBoot\u9879\u76ee\u4e2d\u65b0\u589e\u4e00\u4e2aMyApplicationContext.java\u6587\u4ef6\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a \u7136\u540e [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1542","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/1542","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1542"}],"version-history":[{"count":3,"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/1542\/revisions"}],"predecessor-version":[{"id":1548,"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/1542\/revisions\/1548"}],"wp:attachment":[{"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1542"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1542"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1542"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}