当前位置:首页 » 存储配置 » 应用如何动态加载配置

应用如何动态加载配置

发布时间: 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);
(注意)游戏对象可能不是动态加载时,但是可能他的材质、图集是动态加载的请把这些应用置为空。

热点内容
java16进制字符串 发布:2025-02-05 10:38:13 浏览:643
创业团队配置有哪些 发布:2025-02-05 10:37:40 浏览:630
王者键盘怎么设置安卓 发布:2025-02-05 10:32:01 浏览:373
阿里云轻量服务器ip搭建 发布:2025-02-05 10:24:46 浏览:487
编程高精度 发布:2025-02-05 10:22:28 浏览:230
使命召唤如何配置爆炸狙 发布:2025-02-05 10:08:12 浏览:143
java访问共享目录 发布:2025-02-05 10:03:56 浏览:281
行车记录仪存储卡多大合适 发布:2025-02-05 09:35:21 浏览:112
oppo手机锁屏密码忘了怎么办 发布:2025-02-05 09:33:50 浏览:124
phprsa算法 发布:2025-02-05 09:33:48 浏览:231