我有spring app的application.properties文件,其中包含一些简单的属性:
queue=my.test.q
Run Code Online (Sandbox Code Playgroud)
在java代码中我需要指定@RabbitListener的队列:
@Component
public class Handler {
@RabbitListener(queues = "my.test.q")
public void handleMessage(Message message) {
...
}
Run Code Online (Sandbox Code Playgroud)
这将工作,但我想将参数传递给注释,我尝试了以下但没有一个工作.
@Component
public class Handler {
@Value("${queue}")
private String queueName;
@RabbitListener(queues = @Value("${queue}") <-- not working
@RabbitListener(queues = queueName)) <--- not working
public void handleMessage(Message message) {
...
}
Run Code Online (Sandbox Code Playgroud)
有可能吗?
我有一个在Maven中构建的gwt应用程序,现在我尝试运行一个简单的GWT测试,如下:
public class GwtTestLaughter extends GWTTestCase {
/**
* Specifies a module to use when running this test case. The returned
* module must include the source for this class.
*
* @see com.google.gwt.junit.client.GWTTestCase#getModuleName()
*/
@Override
public String getModuleName() {
return "com.sample.services.joker.laughter.Laughter";
}
/**
* Add as many tests as you like
*/
public void testSimple() {
assertTrue(true);
}
}
Run Code Online (Sandbox Code Playgroud)
在pom.xml文件中,配置gwt-maven-plugin和maven-surefire-plugin如下:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.1.0-1</version>
<configuration>
<!-- Use the 'war' directory for GWT hosted mode -->
<output>${basedir}/war</output>
<webXml>${basedir}/war/WEB-INF/web.xml</webXml>
<runTarget>index.html</runTarget>
<!-- …Run Code Online (Sandbox Code Playgroud) 我有一个字符串(tagList)列表需要在多个线程之间共享进行读取,所以我创建了一个不可修改的版本并将其传递给线程,我不确定它是否是线程安全的,因为线程只读取该列表所以我猜应该没问题?
当我将该不可修改的列表传递给线程时,它是否传递单个副本并由线程共享,还是创建多个副本并将一个副本传递给每个线程?
这是我的代码:
final List<String> tList = Collections.unmodifiableList(tagList);
List<Future<Void>> calls = new ArrayList<Future<Void>>();
FileStatus[] fsta = _fileSystem.listStatus(p);
for (FileStatus sta : fsta) {
final Path path = new Path(sta.getPath(), "data.txt");
if (!_fileSystem.exists(path)) {
continue;
}
else {
calls.add(_exec.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
filterData(path, tList);
return null;
}
}));
}
}
Run Code Online (Sandbox Code Playgroud) 我想为我的REST API端点应用授权过滤器,并且过滤器需要路径参数来进行过滤.这是我的端点和代码:
终点:
curl --url 'localhost:80/reports/resources/org/12345/product/111 ' --request GET --header 'Authorization: <token here>'
Run Code Online (Sandbox Code Playgroud)
资源代码:
@Path("/resources")
public class MyResource extends AbstractResource {
...
@GET
@Path("/org/{orgId}/product/{productId}")
@Produces(MediaType.APPLICATION_JSON)
@RoleAuthenticated
public Response getResourcesReport(@PathParam("orgId") String orgId,
@PathParam("productId") String productId,
@Context HttpHeaders headers){....}
Run Code Online (Sandbox Code Playgroud)
过滤:
@PreMatching
@RoleAuthenticated
public class AuthorizationFilter implements ContainerRequestFilter {
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
MultivaluedMap<String, String> pathparam = requestContext.getUriInfo().getPathParameters(); <-- return empty map
}
Run Code Online (Sandbox Code Playgroud)
我期待requestContext.getUriInfo().getPathParameters()返回以下地图:
orgId 12345
productId 111
Run Code Online (Sandbox Code Playgroud)
怎么回来一张空地图?以及如何从中获取路径参数ContainerRequestContext?
在我们的系统中,我们使用一个设置类来指向属性文件,这取决于它加载不同的属性文件的前夕。要访问特定属性,我们调用'Settings.getString('property_name_here')'。
在我的代码中,我将 @scheduled cron 表达式加载到一个变量并尝试传递给 @scheduled 注释,但它不起作用,
这是我的代码:在属性文件中:
cron.second=0
cron.min=1
cron.hour=14
Run Code Online (Sandbox Code Playgroud)
在构造函数中,我有:
this.cronExpression = new StringBuilder()
.append(settings.getString("cron.second"))
.append(" ")
.append(settings.getString("cron.min"))
.append(" ")
.append(settings.getString("cron.hour"))
.append(" ")
.append("*").append(" ").append("*").append(" ").append("*")
.toString();
Run Code Online (Sandbox Code Playgroud)
它创建了一个“0 1 14 * * *”的字符串,它是一个有效的 con 表达式
在计划任务中,我有:
@Scheduled(cron = "${this.cronExpression}")
public void scheduleTask() throws Exception {
....
}
Run Code Online (Sandbox Code Playgroud)
当我运行代码时它抱怨:引起:java.lang.IllegalStateException:遇到无效的@Scheduled方法'scheduleTask':Cron表达式必须包含6个字段(在“${this.cronExpression}”中找到1个)
然后我将 this.cronExpression 更改为字符串列表:
this.cronExpression = Lists.newArrayList();
this.cronExpression.add(settings.getString("cron.second"));
this.cronExpression.add(settings.getString("cron.min"));
this.cronExpression.add(settings.getString("cron.hour"));
this.cronExpression.add("*");
this.cronExpression.add("*");
this.cronExpression.add("*");
Run Code Online (Sandbox Code Playgroud)
但仍然出现相同的错误,那么 cron 表达式到底应该是什么?
我试图使用gwt的uiBinder来获取图像,但它不会起作用,
在.xml文件中,我定义了:
<ui:with field='res' type="com.my.services.email.client.Resources"/>
<ui:image field="testImage" resource="{res.calIcon}">
我有一个Resources.java文件来定义图像资源:
public interface Resources extends ClientBundle {
Resources INSTANCE = GWT.create(Resources.class);
@Source("img/cal.png")
ImageResource calIcon();
}
和gwt抱怨:
[ERROR] No com.google.gwt.resources.client.ClientBundle$Source annotation and no resources found with default extensions
谁知道这有什么问题?谢谢!
我喜欢 Jsoup 来解析 html,但它们的连接有问题,我需要向同一个网站发送请求,但查询参数不同,比如“id=XXX”,请求如下:
http://website/?id=XXX
Run Code Online (Sandbox Code Playgroud)
我不想为每个 id 创建一个新连接,而是为所有 id 请求保留一个连接,这是我的代码:
Connection conn = null;
..
if (_conn == null) {
_conn = Jsoup.connect("http://website/";
}
doc = _conn.data("id", id).get()
..
Run Code Online (Sandbox Code Playgroud)
但它似乎只适用于第一次,然后每次我的代码运行时重复相同的请求,在这种情况下,即使我在其他时间传递不同的 id,我也只能查询第一个 id。我该如何解决这个问题?
我需要在自己的Java版本上进行切换,Mac OS X 10.8.4但不确定如何,我现在拥有的版本是,1.6.0_51但是我想切换到1.6.0_45:
$ java-版本 Java版本“ 1.6.0_51” Java(TM)SE运行时环境(内部版本1.6.0_51-b11-457-11M4509) Java HotSpot(TM)64位服务器VM(内部版本20.51-b01-457,混合模式) / usr / libexec / java_home -v 1.6.0_43 找不到与版本“ 1.6.0_43”匹配的JVM。 /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
我认为1.6.0_43我的Mac上没有这样的版本?如何安装然后切换到它?谢谢!
我需要在mongodb中找到所有关键字以1-9开头的文档,然后在关键字前添加一个"+",我可以轻松找到文档,但无法弄清楚如何更新它们.
我试过这个,但它不起作用
db.placements.update({program_id:{$in:[113,107]},
keyword:{$regex:'^[0-9]', $options:'i'}},
{keyword:"+"+$keyword})
Run Code Online (Sandbox Code Playgroud)
它无法识别$ keyword,我也试过'.keyword','keyword',它们都不起作用.有没有办法像Java一样引用文档本身,使用'this',所以我可以做类似的事情
this.keyword: "+" + this.keyword
Run Code Online (Sandbox Code Playgroud) 我试图将jquery中的SOAP请求发送给第三方,但始终收到此错误:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><soap:Fault><faultcode>soap:Client</faultcode><faultstring>Problems creating SAAJ object model</faultstring></soap:Fault></soap:Body></soap:Envelope>
我这样做的方法是将令牌传递给另一个函数,该函数基于这些令牌创建SOAP请求。令牌之一是类似这样的HTML字符串:
<tr><td width="2" bgcolor="#ffffff"><\/td><td width="1" bgcolor="#d8dbe3"><\/td><td width="2" bgcolor="#ffffff"><\/td><td width="15" bgcolor="#f5f6f8"><\/td><td width="535" bgcolor="#f5f6f8"><table width="535" cellspacing="0" cellpadding="0" border="0" bgcolor="#f5f6f8"><tr><td width="80"><table width="80" height="96" bgcolor="#999999" cellspacing="0" cellpadding="0" border="0" align="center"><tr><td width="80" height="1" colspan="3"><\/td><\/tr><tr><td width="1" bgcolor="#999999"><\/td>....
Run Code Online (Sandbox Code Playgroud)
每当我添加此令牌时,SOAP请求都会失败。我试图转义该html字符串令牌,SOAP请求成功,但是整个字符串都被所有转义的字符弄乱了,第三方需要此html字符串来呈现模板,因此无论如何我都无法发送转义的版本。有什么办法可以安全地传递html字符串而不会导致请求崩溃?