我了解亚马逊将按GB配置的EBS存储收费.如果我创建我的实例的AMI,这是否意味着我的EBS卷将被复制,因此会产生额外的成本?
在创建和存储AMI(亚马逊机器映像)时是否还有其他成本费用?
如何仅从服务器向特定用户发送websocket消息?
我的webapp具有弹簧安全设置并使用websocket.我遇到了一个棘手的问题,试图只从服务器向特定用户发送消息.
我阅读本手册的理解来自我们可以做的服务器
simpMessagingTemplate.convertAndSend("/user/{username}/reply", reply);
Run Code Online (Sandbox Code Playgroud)
在客户端:
stompClient.subscribe('/user/reply', handler);
Run Code Online (Sandbox Code Playgroud)
但我永远无法调用订阅回调.我尝试了许多不同的路径,但没有运气.
如果我将它发送到/ topic/reply它可以工作,但所有其他连接的用户也会收到它.
为了说明问题,我在github上创建了这个小项目:https://github.com/gerrytan/wsproblem
重现步骤:
1)克隆并构建项目(确保您使用的是jdk 1.7和maven 3.1)
$ git clone https://github.com/gerrytan/wsproblem.git
$ cd wsproblem
$ mvn jetty:run
Run Code Online (Sandbox Code Playgroud)
2)导航到http://localhost:8080,使用bob/test或jim/test登录
3)单击"请求用户特定消息".预期:仅对此用户的"仅收到消息给我"旁边显示消息"hello {username}",实际:未收到任何消息
到目前为止,我的理解是在我们的控制器请求映射方法中,我们可以指定RedirectAttributes参数,并在请求被重定向时使用属性填充它.
示例:
@RequestMapping(value="/hello", method=GET)
public String hello(RedirectAttributes redirAttr)
{
// should I use redirAttr.addAttribute() or redirAttr.addFlashAttribute() here ?
// ...
return "redirect:/somewhere";
}
Run Code Online (Sandbox Code Playgroud)
然后,重定向属性将在重定向到的目标页面上可用.
但是RedirectAttributes类有两种方法:
已经阅读了一段时间的Spring文档,但我有点迷失了.这两者之间的根本区别是什么,我应该如何选择使用哪一个?
我有一个类A,它有一些私有字段,同一个类扩展另一个类B,它也有一些私有字段在A类.
public class A extends B {
private BigDecimal netAmountTcy;
private BigDecimal netAmountPcy;
private BigDecimal priceTo;
private String segment;
private BigDecimal taxAmountTcy;
private BigDecimal taxAmountPcy;
private BigDecimal tradeFeesTcy;
private BigDecimal tradeFeesPcy;
// getter and setter for the above fields
}
Run Code Online (Sandbox Code Playgroud)
而且B级有一些属于A级的私人fiedls
现在,当我尝试从类A上面创建JSON字符串时,我得到以下异常:
class com.hexgen.ro.request.A declares multiple JSON fields named netAmountPcy
Run Code Online (Sandbox Code Playgroud)
如何解决这个问题?
因为它们是私有字段,所以在创建json字符串时应该没有任何问题我猜,但我不确定.
我创建json字符串,如下所示:
Gson gson = new Gson();
tempJSON = gson.toJson(obj);
Run Code Online (Sandbox Code Playgroud)
这里obj是A类的对象
我们的ios6.1-sdk编译的应用程序在ios 6.1 iphone 4,4s和5设备上运行良好.当在ios7 iphone 5s上运行应用程序时,用户界面仍然看起来像ios 6(黑色按钮等),但除了我们发现了一个bug之外,我们对它的大部分都很好.我猜这是因为ios7上的API实现发生了变化.
当我们的应用程序在xcode 5上针对ios7-sdk编译时,一切都崩溃了.UI对象未对齐,标签无法读取等因此我们想要针对ios6.1 sdk编译我们的代码,但是在ios 7上运行它.
在Xcode 5上我安装了ios 6.1 sdk ,如本帖所述,从Xcode 4.6.3 dmg复制它,并在构建设置上将Base SDK更新到ios 6.1,但是当在ios 7模拟器上运行应用程序时,用户界面不会回到ios 6.1.然而,如果应用程序针对运行ios 7的物理iphone进行测试,它会回退到ios 6.1.
在运行ios6-sdk编译的应用程序时,如何使ios 7模拟器回退用户界面,以便我们可以在模拟器上重现该错误?
My Spring应用程序包含两个上下文xml配置文件,第一个root-context.xml仅扫描未@Controller注释的bean:
<beans ...>
<context:component-scan base-package="com.myapp.test">
<context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation"/>
</context:component-scan>
</beans>
Run Code Online (Sandbox Code Playgroud)
第二个servlet-context.xml包含所有spring-mvc设置并扫描带@Controller注释的bean
<beans:beans xmlns="http://www.springframework.org/schema/mvc" ...>
<annotation-driven />
<context:component-scan base-package="com.myapp.test">
<context:include-filter expression="org.springframework.stereotype.Controller" type="annotation"/>
</context:component-scan>
...
</beans:beans>
Run Code Online (Sandbox Code Playgroud)
web.xml上的DispatcherServlet配置如下所示
<web-app ...>
...
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
...
</web-app>
Run Code Online (Sandbox Code Playgroud)
我想尝试基于注释的缓存,所以我将以下bean定义添加到root-context.xml
<cache:annotation-driven/>
<bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager">
<property name="caches">
<set>
<bean class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean" p:name="foo"/>
</set>
</property>
</bean>
Run Code Online (Sandbox Code Playgroud)
并使用带@Service注释的类对其进行测试,该类应由root-context.xml扫描
@Service
public FooService {
@Cacheable("foo")
public …Run Code Online (Sandbox Code Playgroud) 在 DOS 批处理文件中,我可以编写以下循环以按字母升序迭代目录中的文件:
for %f in (*) do (echo %f)
Run Code Online (Sandbox Code Playgroud)
我该如何做同样的事情,但以相反的顺序(字母降序)迭代文件?
我正在尝试通过 ssh 克隆远程 git repo。当我尝试通过 ssh 进入远程主机时,它会提示输入密码并正常工作:
$ ssh gerry@5.12.221.37
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试克隆存储库时,它会出现此错误
$ git clone ssh://gerry@5.12.221.37:/home/gerry/gitrepos/Test.git
ssh: Could not resolve hostname 5.12.221.37:: nodename nor servname provided, or not known
fatal: The remote end hung up unexpectedly
Run Code Online (Sandbox Code Playgroud)
没有任何网络问题,因为我什至可以对 5.12.221.37 端口 22 执行 telnet。
我使用的是 mac osx 10.8,有谁知道我如何解决/解决这个问题?
我一定错过了一个明显的事实 - 一段时间没有编程C++.为什么我不能在将c-style字符串分配给const char*变量后打印它?但是,如果我尝试直接打印它而不指定它工作正常:
#include "boost/lexical_cast.hpp"
using namespace std;
using boost::lexical_cast;
int main (int argc, char** argv)
{
int aa=500;
cout << lexical_cast<string>(aa).c_str() << endl; // prints the string "500" fine
const char* bb = lexical_cast<string>(aa).c_str();
cout << bb << endl; // prints nothing
return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud) 假设浮点数的十进制可视化表示后的2位数(例如:货币),以最小总误差分割金额的最佳方法是什么?
例如,要将100.00平均分配给3个银行账户,我会做这样的事情:
double amount = 100.0;
double acc1 = amount / 3.0;
double acc2 = amount / 3.0;
double acc3 = amount / 3.0;
Run Code Online (Sandbox Code Playgroud)
但是,当用2位小数打印每个帐户余额时,我得到:
printf("%.2f\n", acc1);
printf("%.2f\n", acc2);
printf("%.2f\n", acc3);
33.33
33.33
33.33
Run Code Online (Sandbox Code Playgroud)
很明显,所有帐户的金额总和为99.99,由于四舍五入而损失0.01.
理想情况下,我想要一些功能/算法可以分布几乎相同和视觉打印
33.34
33.33
33.33
Run Code Online (Sandbox Code Playgroud)
这三个账户中的哪一个获得额外的0.01并不重要.
我该怎么做呢?是否有任何舍入算法名称?
java ×4
spring ×3
c++ ×2
spring-mvc ×2
amazon-ec2 ×1
batch-file ×1
boost ×1
c ×1
git ×1
gson ×1
ios ×1
iphone ×1
json ×1
macos ×1
networking ×1
ssh ×1
windows ×1
xcode ×1