小编amg*_*han的帖子

使用2个字段进行猫鼬自定义验证

我想使用mongoose自定义验证来验证endDate是否大于startDate.如何访问startDate值?使用this.startDate时,它不起作用; 我得到了不确定.

var a = new Schema({
  startDate: Date,
  endDate: Date
});

var A = mongoose.model('A', a);

A.schema.path('endDate').validate(function (value) {
  return diff(this.startDate, value) >= 0;
}, 'End Date must be greater than Start Date');
Run Code Online (Sandbox Code Playgroud)

diff 是一个比较两个日期的函数.

mongoose mongodb node.js express

33
推荐指数
5
解决办法
2万
查看次数

使用spring boot和spring-boot-maven-plugin生成war时排除application.properties

我正在使用Spring Boot开发一个Web应用程序,并希望生成war而不是jar.

使用从jar到war的转换,它可以很好地工作:http://spring.io/guides/gs/convert-jar-to-war/

但我想从战争中排除application.properties,因为我@PropertySource(value = "file:${OPENSHIFT_DATA_DIR}/application.properties")用来获取生产环境中的文件路径.

  • 这个方法在生成我的战争时有效,但在eclipse中我无法运行我的应用程序,因为application.properties根本没有复制到目标/类:

    <build>
        <resources> 
            <resource> 
                <directory>src/main/resources</directory> 
                <excludes> 
                    <exclude>application.properties</exclude> 
                </excludes> 
            </resource> 
         </resources> 
    </build>
    
    Run Code Online (Sandbox Code Playgroud)
  • 这个方法根本不起作用,我认为spring-boot-maven-plugin不支持packagingExcludes:

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration> 
                    <packagingExcludes>WEB-INF/classes/application.properties</packagingExcludes> 
                </configuration> 
            </plugin>
        </plugins>
    </build>
    
    Run Code Online (Sandbox Code Playgroud)

你有另一个建议吗?

谢谢

java eclipse spring maven spring-boot

9
推荐指数
2
解决办法
2万
查看次数

弹簧注释@ Scheduled.fixedDelayString不支持Spel

我想在我的属性文件中以秒为单位配置fixedDelay,然后我想在@Scheduled Annotation中将其转换为millis.

我希望这可行:

@Scheduled(fixedDelayString = "#{${my.scheduler.fixed.delay} * 1000}")
Run Code Online (Sandbox Code Playgroud)

但它抛出了这个例外

Caused by: java.lang.IllegalStateException: Encountered invalid @Scheduled method 'myMethod': Invalid fixedDelayString value "#{5 * 1000}" - cannot parse into integer
at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.processScheduled(ScheduledAnnotationBeanPostProcessor.java:384) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor$1.doWith(ScheduledAnnotationBeanPostProcessor.java:227) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]
Run Code Online (Sandbox Code Playgroud)

$ {my.scheduler.fixed.delay}已被正确恢复,但表达式未被重新开发.

我试图配置自己的StringValueResolver

private static class CustomValueResolver
    implements StringValueResolver {

    private final ConfigurableBeanFactory beanFactory;

    private final ExpressionParser expressionParser;

    public CustomValueResolver(final ConfigurableBeanFactory beanFactory, final ExpressionParser expressionParser) {

        this.beanFactory = beanFactory;
        this.expressionParser = expressionParser;
    }

    @Override
    public String resolveStringValue(
        final String strVal) {

        String value = this.beanFactory.resolveEmbeddedValue(strVal);
        if …
Run Code Online (Sandbox Code Playgroud)

java spring spring-annotations spring-el

9
推荐指数
1
解决办法
1811
查看次数

AWS Cognito Mock

我想为我的基于nodejs的API编写BDD测试,该API使用AWS cognito作为用户身份验证服务,但我不希望每次构建运行时都能获得真正的cognito服务.

是否有一种简单而优雅的方式来模拟Cognito调用.

使用过的框架:

  • Nodejs(Hapi.js)
  • nodejs的aws-sdk

amazon-web-services node.js hapijs amazon-cognito aws-sdk

6
推荐指数
1
解决办法
3683
查看次数