我有一个Spring应用程序,我想动态更改数据源,即.当输入DS URL时,Spring bean和所有依赖项将自动更新.我知道这有点奇怪,但无论如何我想实现它.我的Spring配置如下:
<bean id="majorDataSource" class="org.postgresql.ds.PGSimpleDataSource">
<property name="serverName" value="${jdbc.serverName}" />
<property name="portNumber" value="${jdbc.portNumber}" />
<property name="user" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="databaseName" value="${jdbc.databaseName}" />
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="majorDataSource"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="majorDataSource"/>
<property name="configLocation" value="classpath:sqlmap-config.xml"/>
</bean>
Run Code Online (Sandbox Code Playgroud)
问题是:
JDBC URL存储在属性中,可以在运行时更改.
更改URL后,我需要重新创建数据源,也可能是依赖对象.我无法弄清楚如何在Spring中优雅地做到这一点?
我知道Spring可以基于一个键动态地路由数据源,但数据源URL是在Spring中预定义的,不会改变运行时.这不是我的情况.
我需要从Java网站上的SSL证书中提取到期日期,应该支持可信和自签名证书,例如:1.trusted https://github.com 2.self-signed https://mms.nw .RU /
我已经将一些代码复制为:
import java.net.URL;
import java.security.SecureRandom;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.KeyManager;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
public class SSLTest {
public static void main(String [] args) throws Exception {
// configure the SSLContext with a TrustManager
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(new KeyManager[0], new TrustManager[] {new DefaultTrustManager()}, new SecureRandom());
SSLContext.setDefault(ctx);
URL url = new URL("https://github.com");//https://mms.nw.ru
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
conn.setHostnameVerifier(new HostnameVerifier() {
@Override
public boolean …
Run Code Online (Sandbox Code Playgroud) 我正在使用jMeter来测试Tomcat应用程序.我需要解析jMeter响应并发出第二个请求.第一个响应如下:
<responseData class="java.lang.String"><html>
<body>
ERROR=0
MSG=N/A
FILELIST=1555;1340778737370;1526545487;
VERSION=1.002
URL=https://192.168.100.46/updserver/download?action=signature_download&token=
INTERVAL=0
</body>
</html>
</responseData>
Run Code Online (Sandbox Code Playgroud)
我需要提取"FILELIST"和"URL"变量并将它们注入新的URL:
https://192.168.100.46/updserver/download?action=signature_download&token=1555;1340778737370;1526545487;
Run Code Online (Sandbox Code Playgroud)
我知道有一些后处理器可以做到这一点,但不知道如何做到这一点.顺便说一下,第二个请求会从Tomcat servlet下载一些文件,有没有办法让jMeter只下载流但不写入物理文件?这样我就可以对我的servlet进行负载性能测试.
我使用JMeter进行Web服务器的性能测试.我的测试用例如下:
step1: send file update request to server.
step2: server will return some files URL as html response
step3: client need to create new request with the URL returned in step2,thus need to parse
the response of step2.
Run Code Online (Sandbox Code Playgroud)
我是JMeter的新手,不知道如何实现它.我基本上学习了关于预处理器和后处理器的JMeter,但仍然没有关于如何做的线索.
我已经用谷歌搜索505是"不支持HTTP版本",但仍然无法弄清楚我的问题.我有一个带Tomcat的Web应用程序,服务器端带有自签名证书以启用HTTPS,无需验证客户端.客户端将验证服务器证书.我已经分析了wireshark数据包,看来SSL握手是正确的.但是当我检查Tomcat localhost_access_log时,客户端请求会出现505错误,服务器端也没有收到客户端请求.你能帮忙提一下这个吗?
172.25.21.113 - - [24/May/2012:16:28:26 +0800] "GET /updserver/update?action=signature_update&device_type=NGN&service_type=KAV&engine_ver=1.00&sig_ver=4.123&mac=0019CB72736E HTTP/1.1 " 505 -
Run Code Online (Sandbox Code Playgroud) 我有AWS账号和信息电子邮件地址/访问密钥/安全密钥,没有任何其他密码,我找不到登录AWS服务的位置,如EC2等?
我有一个重复的python日程安排任务如下,需要在startMonitor()中每3分钟运行一次getMyStock():
from stocktrace.util import settings
import time, os, sys, sched
schedule = sched.scheduler(time.time, time.sleep)
def periodic(scheduler, interval, action, actionargs=()):
scheduler.enter(interval, 1, periodic,
(scheduler, interval, action, actionargs))
action(*actionargs)
def startMonitor():
from stocktrace.parse.sinaparser import getMyStock
periodic(schedule, settings.POLLING_INTERVAL, getMyStock)
schedule.run( )
Run Code Online (Sandbox Code Playgroud)
问题是:
1.当某些用户事件发生时,我可以取消或停止计划吗?
2.有没有其他python模块可以更好地重复调度?就像java quartz一样?
我需要在Apache HTTP Server下部署django应用程序,我还需要实时向客户端的Web浏览器推送事件.我对python很新,有人会建议一些websocket服务器可以在Python + Django + Apache中运行吗?
我有许多线程同时读取相同的文件(完全约100M),只有一个线程来更新文件.我想将文件映射到内存中以减少文件I/O. 如何在Java中完成?
我基本上考虑了以下两种方法:
我不确定这些方法是否应该有效.如果有更好的解决方案,请帮助提供一些提示.
我编写了一个处理财务数据处理的 Djano 应用程序。我必须从 MySQL 表加载大数据(超过 1000000 条记录),并将记录转换为 django 视图中的 JSON 数据,如下所示:
trades = MtgoxTrade.objects.all()
data = []
for trade in trades:
js = dict()
js['time']= trade.time
js['price']= trade.price
js['amount']= trade.amount
js['type']= trade.type
data.append(js)
return data
Run Code Online (Sandbox Code Playgroud)
问题是FOR循环非常慢(200000条记录需要9秒以上),有没有有效的方法在Python中将DB记录转换为JSON格式数据?
更新:我已经根据 Mike Housky 在我的 ENV(ActivePython2.7,Win7) 中的答案运行代码,代码更改和结果为:
def create_data(n):
from api.models import MtgoxTrade
result = MtgoxTrade.objects.all()
return result
Build ............ 0.330999851227
For loop ......... 7.98400020599
List Comp. ....... 0.457000017166
Ratio ............ 0.0572394796312
For loop 2 ....... 0.381999969482
Ratio ............ 0.047845686326
Run Code Online (Sandbox Code Playgroud)
你会发现for循环大约需要8秒!如果我注释掉 For 循环,那么 List …
我使用 pika 与 RabbitMQ 服务器交互,如下所示: 1. P1 向 RabbitMQ 发送消息 2. C1 是一个 pyqt4 桌面托盘应用程序,收到后将显示上述消息。代码如下:
import sip
sip.setapi('QVariant', 2)
from PyQt4 import QtCore, QtGui
import systray_rc
class Window(QtGui.QDialog):
def __init__(self):
super(Window, self).__init__()
self.createIconGroupBox()
self.createMessageGroupBox()
self.iconLabel.setMinimumWidth(self.durationLabel.sizeHint().width())
self.createActions()
self.createTrayIcon()
self.showMessageButton.clicked.connect(self.showMessage)
self.showIconCheckBox.toggled.connect(self.trayIcon.setVisible)
self.iconComboBox.currentIndexChanged.connect(self.setIcon)
self.trayIcon.messageClicked.connect(self.messageClicked)
self.trayIcon.activated.connect(self.iconActivated)
mainLayout = QtGui.QVBoxLayout()
mainLayout.addWidget(self.iconGroupBox)
mainLayout.addWidget(self.messageGroupBox)
self.setLayout(mainLayout)
self.iconComboBox.setCurrentIndex(1)
self.trayIcon.show()
self.setWindowTitle("Systray")
self.resize(400, 300)
def setVisible(self, visible):
self.minimizeAction.setEnabled(visible)
self.maximizeAction.setEnabled(not self.isMaximized())
self.restoreAction.setEnabled(self.isMaximized() or not visible)
super(Window, self).setVisible(visible)
def closeEvent(self, event):
if self.trayIcon.isVisible():
QtGui.QMessageBox.information(self, "Systray",
"The program will keep running in the system …
Run Code Online (Sandbox Code Playgroud) 我在AWS EC2上执行以下操作:
基本上我想知道:
提前致谢.我无法从谷歌或EC2文件中弄清楚.
我使用django_tables2(http://django-tables2.readthedocs.org/en/latest/)进行HTML表格渲染,但我的模板无法工作:
{% extends 'base.html' %}
{% block main %}
{% render_table table %}
{% endblock %}
Run Code Online (Sandbox Code Playgroud)
错误消息如下:
Invalid block tag: 'render_table', expected 'endblock'
Run Code Online (Sandbox Code Playgroud)
是否有上述tables2插件的替代品?
python ×4
django ×3
java ×3
jmeter ×2
ssl ×2
amazon-ec2 ×1
concurrency ×1
datasource ×1
file-io ×1
httpclient ×1
https ×1
json ×1
nio ×1
pika ×1
python-2.7 ×1
rabbitmq ×1
socket.io ×1
spring ×1
tomcat ×1
tornado ×1
websocket ×1