标题可能不是很清楚,这里是问题
我正在以这种形式执行更新:
db.poi.update({
_id: ObjectId("50f40cd052187a491707053b"),
"votes.userid": {
"$ne": "50f5460d5218fe9d1e2c7b4f"
}
},
{
$push: {
votes: {
"userid": "50f5460d5218fe9d1e2c7b4f",
"value": 1
}
},
$inc: { "score":1 }
})
Run Code Online (Sandbox Code Playgroud)
仅当没有具有相同用户 ID 的文档时才在数组中插入文档(解决方法,因为唯一索引不适用于数组)。该代码在 mongo 控制台中运行良好。从我的应用程序中,我正在使用这个:
@Override
public void vote(String id, Vote vote) {
Query query = new Query(Criteria.where("_id").is(id).and("votes.userid").ne(vote.getUserid()));
Update update = new Update().inc("score", vote.getValue()).push("votes", vote);
mongoOperations.updateFirst(query, update, Poi.class);
}
Run Code Online (Sandbox Code Playgroud)
如果作为“userid”,我使用一个不能是 mongo ObjectId 的字符串,这很好用,但是如果我在示例中使用该字符串,则执行的查询会像这样转换(来自 mongosniff):
update flags:0 q:{ _id: ObjectId('50f40cd052187a491707053b'), votes.userid: { $ne: ObjectId('50f5460d5218fe9d1e2c7b4f') } } o:{ $inc: { score: 1 }, $push: { …Run Code Online (Sandbox Code Playgroud) 我有一个滑块,在输入上使用html5,例如
<input id="sliderWidget" title="Slide me" type="range" min="1" max="1.6" step="0.3" value="1.3">
Run Code Online (Sandbox Code Playgroud)
我一直在尝试使用硒来改变滑块,但传统的图像滑块控件对我来说并不适用....例如
Action dragAndDrop = builder.dragAndDropBy(sliderWidget,0,30).build();
dragAndDrop.perform();
Run Code Online (Sandbox Code Playgroud)
有没有人有任何想法如何我可以执行这种增量范围变化
提前致谢
我需要以下建议:
我有一个@Scheduled服务方法,它有一个几秒钟的fixedDelay,它可以扫描一个工作队列并在找到任何工作队列时处理合适的工作.在同一个服务中,我有一个方法将工作放入工作队列,我希望这个方法在完成后立即触发队列扫描(因为我确信现在有一些工作要做扫描器)为了避免计划踢的延迟(因为这可能是秒,时间有点关键).
任务执行和Scheaduling子系统的"现在触发"功能将是理想的,也可以在手动启动执行后重置fixedDelay(因为我不希望我的手动执行与计划的冲突).注意:队列中的工作可以来自外部源,因此需要定期扫描.
欢迎任何建议
编辑:队列存储在基于文档的数据库中,因此本地基于队列的解决方案不合适.
我不太满意的解决方案(不喜欢使用原始线程)会是这样的:
@Service
public class MyProcessingService implements ProcessingService {
Thread worker;
@PostCreate
public void init() {
worker = new Thread() {
boolean ready = false;
private boolean sleep() {
synchronized(this) {
if (ready) {
ready = false;
} else {
try {
wait(2000);
} catch(InterruptedException) {
return false;
}
}
}
return true;
}
public void tickle() {
synchronized(this) {
ready = true;
notify();
}
}
public void run() {
while(!interrupted()) {
if(!sleep()) continue;
scan();
} …Run Code Online (Sandbox Code Playgroud) 这部分代码被声纳中的pmd拒绝:
public String getFoo() {
String foo = System.getProperty("foo");
if (foo == null) {
foo = System.getenv("foo");
} else if (foo == null) {
foo = "defaultFoo";
}
return foo;
}
Run Code Online (Sandbox Code Playgroud)
它说"在条件下避免文字".有人能告诉我这个或这个规则试图产生什么问题吗?
我使用Spring引导1.5.2.RELEASE并不能纳入JSR - 349(Bean验证1.1),用于@RequestParam与@PathVariable在方法本身.
对于POST请求,如果方法参数是Java POJO,那么注释该参数与@Valid工作正常但注释@RequestParam和@PathVariable类似@NotEmpty,@Email不工作.
我有Spring的注释控制器类 @Validated
关于SO有很多问题,我对这个答案发表了评论,认为它不适用于我.
Spring Boot包括 - validation-api-1.1.0.Final.jar和hibernate-validator-5.3.4.Final.jar.
我错过了什么吗?
示例代码,
@RequestMapping(method = RequestMethod.GET, value = "/testValidated", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseBean<String> testValidated(@Email @NotEmpty @RequestParam("email") String email) {
ResponseBean<String> response = new ResponseBean<>();
response.setResponse(Constants.SUCCESS);
response.setMessage("testValidated");
logger.error("Validator Not called");
return response;
}
Run Code Online (Sandbox Code Playgroud)
下面的处理程序永远不会被调用当我发送空值或者没有良好形成的电子邮件地址时,email&control总是用in testValidated方法.
@ExceptionHandler(ConstraintViolationException.class)
@ResponseBody
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ResponseBean handle(ConstraintViolationException exception) {
StringBuilder …Run Code Online (Sandbox Code Playgroud) 由于尚未发布Spring-Data-Hadoop,因此很难找到与cloudera一起使用的运行示例配置.
我需要选择哪些依赖项来与CDH4(Hadoop 2.0.0-cdh4.1.3)一起运行Spring-Data-Hadoop?
通过选择不同的apporches,我得到了这个例外:
空指针
Exception in thread "SimpleAsyncTaskExecutor-1" java.lang.ExceptionInInitializerError
at org.springframework.data.hadoop.mapreduce.JobExecutor$2.run(JobExecutor.java:183)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.NullPointerException
at org.springframework.util.ReflectionUtils.makeAccessible(ReflectionUtils.java:405)
at org.springframework.data.hadoop.mapreduce.JobUtils.<clinit>(JobUtils.java:123)
... 2 more
Run Code Online (Sandbox Code Playgroud)版本不匹配7到4
Caused by: org.apache.hadoop.ipc.RemoteException: Server IPC version 7 cannot communicate with client version 4
at org.apache.hadoop.ipc.Client.call(Client.java:1070)
at org.apache.hadoop.ipc.RPC$Invoker.invoke(RPC.java:225)
at $Proxy1.getProtocolVersion(Unknown Source)
at org.apache.hadoop.ipc.RPC.getProxy(RPC.java:396)
at org.apache.hadoop.ipc.RPC.getProxy(RPC.java:379)
at org.apache.hadoop.hdfs.DFSClient.createRPCNamenode(DFSClient.java:119)
at org.apache.hadoop.hdfs.DFSClient.<init>(DFSClient.java:238)
at org.apache.hadoop.hdfs.DFSClient.<init>(DFSClient.java:203)
at org.apache.hadoop.hdfs.DistributedFileSystem.initialize(DistributedFileSystem.java:89)
at org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:1386)
at org.apache.hadoop.fs.FileSystem.access$200(FileSystem.java:66)
at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:1404)
at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:254)
at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:123)
at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:238)
at org.apache.hadoop.fs.Path.getFileSystem(Path.java:187)
at org.apache.hadoop.mapreduce.lib.input.FileInputFormat.addInputPath(FileInputFormat.java:372)
at org.springframework.data.hadoop.mapreduce.JobFactoryBean.afterPropertiesSet(JobFactoryBean.java:208)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1545)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1483)
... …Run Code Online (Sandbox Code Playgroud)我有一些文件列表(.jil)。我想使用maven-assembly-plugin将它们附加到构建中。
我毫不费力地以“ zip”格式部署它们。
但是,“ dir”格式引发异常:
[警告]汇编文件:C:\ Branches \ project-branch \ target \ project \ output \目录不是常规文件(可能是目录)。不能将其附加到项目版本以进行安装或部署。
pom文件:
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>make-devq</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>
${basedir}/environments/dev/assembly/descriptor.xml
</descriptor>
</descriptors>
<finalName>project</finalName>
<appendAssemblyId>true</appendAssemblyId>
<workDirectory>
${project.build.directory}/${project.artifactId}/work/project
</workDirectory>
<outputDirectory>
${project.build.directory}/${project.artifactId}/output
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
程序集描述符:
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>project-id</id>
<formats>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${basedir}/environments/dev/jils/</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>*.jil</include>
</includes>
</fileSet>
</fileSets>
</assembly>
Run Code Online (Sandbox Code Playgroud) 有没有办法在 ECJ 中编译 lomboked 代码而不将 lombok 设置为 maven 进程的javaaagent?
下面的代码片段仅在我使用 lombok 作为代理运行 mvn 时才有效
<profile>
<id>ecj</id>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerId>eclipse</compilerId>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-eclipse</artifactId>
<version>2.8-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.8</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
Run Code Online (Sandbox Code Playgroud)
MAVEN_OPTS=-javaagent:lombok.jar mvn -P ecj 结果编译成功。
然而,运行只会mvn -P ecj产生通常的非龙目岛错误,例如:__ cannot be resolved to a type
我尝试使用com.reubenpeeris.maven:lombok-eclipse-compiler:1.3
但失败了Compilation failure
Unrecognized option: target/generated-sources/annotations,我认为这意味着这个编译器太旧了。
我也尝试添加
<fork>true</fork>
<compilerArgs>
<arg>-javaagent:lombok.jar</arg>
</compilerArgs>
Run Code Online (Sandbox Code Playgroud)
但它似乎没有任何效果。
我想知道 postgres 中的“pg_stat_statements”视图。数据的时间范围是什么?它是否显示过去 24 小时内执行的查询或执行的整体查询?由于该表不包含任何时间戳。
是否可以将 Spring Bean 暴露给 Micronaut 应用程序,并将它们与 @Autowired 一起使用,或 @Inject 它们到 Micronaut 应用程序中,并通过 Maven pom.xml 将 Spring Beans 项目作为 Maven 依赖项添加到 Micronaut 项目中?
该指南: https: //micronaut-projects.github.io/micronaut-spring/latest/guide/ 讨论“将 Micronaut Bean 暴露给 Spring 应用程序”,但反之则不然。
我想在 Micronaut 应用程序中使用的 Spring Bean 是使用 @Repository、@Component、@Service、@Configuration 公开的。
这是否可能,是否是在 Micronaut 应用程序本身中定义 Spring Bean 的先决条件,以及是否支持使用库(定义了 Spring Beans 的 JAR 文件)作为 Micronaut 应用程序的依赖项?
每当我尝试 @Autowire 或 @Inject 在与 Micronaut 应用程序不同的应用程序中定义的 Spring Bean(前者已作为 pom.xml 中的依赖项添加到其中)时,我会收到以下异常:
io.micronaut.context.exceptions.DependencyInjectionException: Failed to inject value for field [fieldName] of class: MicronautClassName_From_Where_I_have_Referrenced_the_Spring_Bean
Path Taken: Class.fieldName
at io.micronaut.context.AbstractBeanDefinition.getBeanForField(AbstractBeanDefinition.java:1462)
at …Run Code Online (Sandbox Code Playgroud) java ×7
maven ×2
spring-boot ×2
spring-data ×2
autowired ×1
cloudera ×1
database ×1
eclipse ×1
hadoop ×1
html5 ×1
jsr ×1
lombok ×1
micronaut ×1
mongodb ×1
pmd ×1
postgresql ×1
queue ×1
range ×1
selenium ×1
sonarqube ×1
spring ×1
spring-bean ×1
spring-mvc ×1
sql ×1