當前位置:首頁 » 存儲配置 » 應用如何動態載入配置

應用如何動態載入配置

發布時間: 2023-06-14 16:56:40

❶ spring如何動態載入配置文件,就是配置文件修改了,application.xml如何能讀取到

項目,需要訪問多個資料庫,而且需要在伺服器運行不重新啟動的情況下,動態的修改spring中配置的數據源datasource,在網上找了很多資料,最後找到了適合我的方法,下面總結一下。
spring的配置文件是在容器啟動的時候就載入到內存中的,如果手動改了application.xml,我們必須要重新啟動伺服器配置文件才會生效。而在spring中提供了一個類WebApplicationContext,這個類可以讓你獲得一些bean,可以修改內存中的信息,我就是通過這個類來實現的。下面是我具體的代碼。

package com.southdigital.hospital;

import java.io.IOException;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.mchange.v2.c3p0.ComboPooledDataSource;

public class ChangeSpringConfig extends HttpServlet
{

private String ipAddress = "127.0.0.1";

/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
doPost(request, response);
}

/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
//先取得servleContext對象,提供給spring的WebApplicationUtils來動態修改applicationContext.xml

ipAddress = request.getParameter("ipAddress");
System.out.println(ipAddress);

ServletContext servletContext = this.getServletContext();
WebApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext);
ComboPooledDataSource cpds = (ComboPooledDataSource) applicationContext.getBean("dataSource");
cpds.setJdbcUrl("jdbc:mysql://"+ipAddress+":3306/ssh");

}

}
注意:通過這種方法修改applicationContext.xml文件的時候用c3p0,而不可以用dbcp,dbcp不支持動態修改讀取到內存裡面的數據。
spring 3.1已經支持了。

❷ android中怎麼動態的載入一個布局

由於前段時間項目需要,需要在一個頁面上載入根據不同的按鈕載入不同的布局頁面,當時想到用 tabhot 。不過美工提供的界面圖完全用不上tabhot ,所以想到了動態載入的方法來解決這一需求。在這里我整理了一下,寫了一個 DEMO 希望大家以後少走點彎路。

首先,我們先把界面的框架圖畫出來,示意圖如下:

❸ unity3d 怎麼動態載入預置

Unity3D 里有兩種動態載入機制:一個是Resources.Load,另外一個通過AssetBundle,其實兩者區別不大。 Resources.Load就是從一個預設打進程序包里的AssetBundle里載入資源,而一般AssetBundle文件需要你自己創建,運行時動態載入,可以指定路徑和來源的。
(1).assetBundle就是內部數據讀取完後自動創建了一個assetBundle而已Create完以後,等於把硬碟或者網路的一個文件讀到內存一個中,這時也就是個AssetBundle內存鏡像數據塊。釋放方式是AssetBundle.Unload(false)
(2).用AssetBundle.Load(同Resources.Load) 會從AssetBundle的內存鏡像里讀取並創建一個Asset對象,使用Resources.UnloadUnusedAssets()釋放全部和Resources.UnloadAsset(gameobject);釋放單個;
(3).Instaniate一個Prefab,是一個對Assets進行Clone(復制)+引用結合的過程,使用GameObject.Destroy(gameobject);
(注意)游戲對象可能不是動態載入時,但是可能他的材質、圖集是動態載入的請把這些應用置為空。

熱點內容
sql語句on 發布:2025-02-05 07:41:42 瀏覽:596
取消電腦密碼怎麼設置8 發布:2025-02-05 07:24:16 瀏覽:393
洗腦編程 發布:2025-02-05 07:23:52 瀏覽:948
osd加密 發布:2025-02-05 07:17:39 瀏覽:36
微信游戲源碼下載 發布:2025-02-05 07:17:29 瀏覽:384
計算機內存儲器是 發布:2025-02-05 07:13:35 瀏覽:144
classpathlinux 發布:2025-02-05 07:12:57 瀏覽:564
linuxftp連接失敗 發布:2025-02-05 07:01:40 瀏覽:705
學生信息管理系統java 發布:2025-02-05 06:58:45 瀏覽:576
刺客信條4解壓後 發布:2025-02-05 06:55:23 瀏覽:901