为了账号安全,请及时绑定邮箱和手机立即绑定

spring cloud config server可以加载多个配置文件么

/ 猿问

spring cloud config server可以加载多个配置文件么

万千封印 2019-03-03 10:04:03

spring cloud config server可以加载多个配置文件么


查看完整描述

2 回答

?
慕盖茨4494581

项目需要访问数据库且需要服务器运行重新启情况态修改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.

*
* 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.

*
* 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象提供给springWebApplicationUtils态修改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,用dbcpdbcp支持态修改读取内存面数据
spring 3.1已经支持



查看完整回答
反对 回复 2019-03-10
?
波斯汪

jdbc连接池于场景说都足够既用spring管理建议使用连接池另外spring自身没实现连接池般都第三连接池包装见C3P0dbcp及近比较流行boneCP等

查看完整回答
反对 回复 2019-03-10
  • 2 回答
  • 0 关注
  • 537 浏览
我要回答

相关问题推荐

慕课专栏
更多

添加回答

回复

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信