小编212*_*212的帖子

将spring @value注释评估为原始布尔值

我有一个spring @configuration注释类MappingsClientConfig,其布尔字段为:

 @Value("${mappings.enabled:true}")
    private boolean mappingsEnabled;
Run Code Online (Sandbox Code Playgroud)

这个类被导入另一个spring注释类,如下所示:

@Configuration
@Import(MappingsClientConfig.class)
public class LookupManagerConfig {
Run Code Online (Sandbox Code Playgroud)

当在测试用例中通过Spring上下文实例化类时,容器无法将字符串解析为布尔字段mappingsEnabled,我得到:

Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private boolean com.barcap.tcw.mappings.economic.client.config.EconomicMappingsClientConfig.economicMappingsEnabled; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'boolean'; nested exception is java.lang.IllegalArgumentException: Invalid boolean value [${mappings.enabled:true}]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:502)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:282)
    ... 138 more
Caused by: org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'boolean'; nested exception is java.lang.IllegalArgumentException: Invalid boolean value [${mappings.enabled:true}]
    at org.springframework.beans.SimpleTypeConverter.convertIfNecessary(SimpleTypeConverter.java:61) …
Run Code Online (Sandbox Code Playgroud)

spring annotations

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

尾部多个文件和grep输出

我想从多个日志文件中获取一个模式,这些日志文件会被某些进程不断更新,并且会连续地延迟这个grep的输出.下面的命令不起作用,我得到

  • tail:警告:无限期地遵循标准输入是无效的
tail -f  | grep --line-buffered "Search this: " /var/links/proc2/id/myprocess*/Daily/myprocess*.log
Run Code Online (Sandbox Code Playgroud)

有人可以解决这个问题吗?

unix grep tail

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

如何在Java 8中引用reduce()操作的结果?

我试图mkString在Java8中编写一个函数,一个Scala是有用的,mkString并遇到了两个问题,我可以使用一些帮助:

  1. 我无法创建mkString泛型Collection引用的第一个参数,Collection<Object> c并且让调用者使用任何类型的集合调用.

  2. 无法引用内联返回的结果reduce()来访问结果的长度以删除额外的前导分隔符.

这是代码:

public static void main(String[] args) {
    List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);
    System.out.println(mkString(numbers, ","));

}

public static String mkString(Collection<Integer> c, String sep) {
    return c.stream()
            .map(e -> String.valueOf(e))
            .reduce("", (a, b) -> a + sep + b)
            .substring(1, <<>>.length);
}
Run Code Online (Sandbox Code Playgroud)

java reduce lambda scala java-stream

11
推荐指数
2
解决办法
358
查看次数

对案例类字段的简单迭代

我正在尝试编写一个泛型方法来迭代案例类的字段:

case class PriceMove(price: Double, delta: Double)

def log(pm : PriceMove) { info("price -> " + price + " delta -> " + delta)}

我需要log能够处理任何案例类.什么只需要log处理case类的参数类型和实际的泛型字段迭代代码?

scala case-class

7
推荐指数
1
解决办法
9970
查看次数

标签 统计

scala ×2

annotations ×1

case-class ×1

grep ×1

java ×1

java-stream ×1

lambda ×1

reduce ×1

spring ×1

tail ×1

unix ×1