我在mongodb中有这些数据:
{
"name": "Amey",
"country": "India",
"region": "Dhule,Maharashtra"
}
Run Code Online (Sandbox Code Playgroud)
我希望在将字段名称作为查询中的变量传递时检索数据.
以下不起作用:
var name = req.params.name;
var value = req.params.value;
collection.findOne({name: value}, function(err, item) {
res.send(item);
});
Run Code Online (Sandbox Code Playgroud)
如何查询mongodb保持字段名称及其值动态?
http://docs.aws.amazon.com/general/latest/gr/api-retries.html
本文档提到"每个AWS SDK实现自动重试逻辑,AWS SDK for Java自动重试请求".
如果我没有指定任何重试配置,那么Java AWS SDK的默认机制是什么?如果AWS服务端出现故障,我一直在使用Java AWS SDK并获得简单的服务异常.我从未经历过任何"自动"重试机制.有人可以解释一下这种重试机制是什么吗?
我有一个使用render_template的烧瓶web应用程序,如下所示.我需要在响应中添加Content-Security-Policy作为附加的http响应头.我尝试了下面的方法,但都失败了,给了我500.
1.
from flask import \
Flask, \
render_template
app = Flask(__name__,template_folder='tmpl')
@app.route('/')
def index():
resp =make_response(render_template('index.html'))
resp.headers['Content-Security-Policy']='default-src \'self\''
return resp
if __name__ == '__main__':
app.run(host='0.0.0.0', port=3001)
Run Code Online (Sandbox Code Playgroud)
2.
@app.route('/')
def index():
resp =render_template('index.html')
resp.headers.add('Content-Security-Policy','default-src \'self\'')
return resp
if __name__ == '__main__':
app.run(host='0.0.0.0', port=3001)
Run Code Online (Sandbox Code Playgroud)
这可能有什么不对?
在终端上,当我以webhost:3001访问Web应用程序时,我会看到以下内容
127.0.0.1 - - [06/Apr/2015 01:45:01]"GET/HTTP/1.1"500 -
我正在尝试在 Fedora 机器上构建一个 java 项目 http://sourceforge.net/projects/fuse-j/?source=typ_redirect。编译 JNI 绑定时编译失败。
生成文件
include ../build.conf
include ../jvm_ldpath.def
SRCS := javafs.c javafs_bindings.c
HDRS := javafs.h javafs_bindings.h
LIB_SO := libjavafs.so
INCLUDES := -I${FUSE_HOME}/include -I${JDK_HOME}/include -I${JDK_HOME}/include/linux
LDPATH := ${LDPATH} -L${FUSE_HOME}/lib
all: ${LIB_SO}
${LIB_SO}: ${SRCS} ${HDRS}
gcc -fPIC -shared -D_FILE_OFFSET_BITS=64 -o ${LIB_SO} ${INCLUDES} ${LDPATH} -ljvm -lfuse -lpthread ${SRCS}
clean:
rm -f ${LIB_SO}
Run Code Online (Sandbox Code Playgroud)
错误:
/bin/ld: cannot find -ljvm
collect2: error: ld returned 1 exit status
Makefile:17: recipe for target 'libjavafs.so' failed
make[1]: *** [libjavafs.so] Error
Run Code Online (Sandbox Code Playgroud)
JDK_HOME ,FUSE_HOME 设置正确。你能建议这里有什么问题吗?
我正在定义要检查的条件,以便以后动态加载服务接口的两个实现之一。
@Component
public class IsPolicyEnabled implements Condition {
@Autowired
private MyProperties props;
@Override
public boolean matches(ConditionContext arg0, AnnotatedTypeMetadata arg1) {
return props.isPolicyEnabled();
}
}
Run Code Online (Sandbox Code Playgroud)
和
@Component
public class MyProperties {...}
Run Code Online (Sandbox Code Playgroud)
和
@Service
@Conditional(IsPolicyEnabled.class)
public class ServiceA implements Service {...}
Run Code Online (Sandbox Code Playgroud)
但是,我遇到了运行时错误。
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: java.lang.NullPointerException
at com.xyz.utils.IsPolicyEnabled.matches(IsPolicyEnabled.java:9)
at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:108)
at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:88)
at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:71)
at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.isConditionMatch(ClassPathScanningCandidateComponentProvider.java:515)
Run Code Online (Sandbox Code Playgroud)
基本上,它无法初始化已经自动连接到条件实现中的props对象。那是不允许的吗?
由于条件评估依赖于该依赖关系提供的值,因此我该如何自动在条件实现内部连接另一个依赖关系?
public class ProjectIdInitializer {
public static void setProjectId(String projectId) {
//load spring context which i want to escape in my test
}
}
public class MyService {
public Response create(){
...
ProjectIdInitializer.setProjectId("Test");
}
}
@RunWith(PowerMockRunner.class)
@PrepareForTest({ProjectIdInitializer.class})
public class MyServiceTest{
@InjectMocks
private MyService myServiceMock ;
public void testCreate() {
PowerMockito.mockStatic(ProjectIdInitializer.class);
PowerMockito.doNothing().when(ProjectIdInitializer.class, "setProjectId", Mockito.any(String.class));
// Does not work,still tries to load spring context
Response response=myServiceMock .create();
}
Run Code Online (Sandbox Code Playgroud)
如果从myservice调用ProjectIdInitializer.setProjectId(),我如何确保没有任何反应?
java ×4
amazon-ec2 ×1
annotations ×1
aws-java-sdk ×1
express ×1
flask ×1
fuse ×1
gcc ×1
header ×1
junit ×1
linux ×1
mocking ×1
mongodb ×1
node.js ×1
powermock ×1
python ×1
spring ×1
spring-4 ×1
spring-boot ×1
web ×1