小编Jig*_*aik的帖子

声纳-将DATE_FORMAT设置为实例变量

我有一个休息的Web服务,下面是我如何声明DateFormat的信息,因为这是我将在应用程序范围内使用的日期格式。

当我使用SonarLint eclipse插件进行代码分析时,我得到重大警告,提示“将DATE_FORMAT用作实例变量”。

public class Constants {

    private Constants() {

    }

    public static final DateFormat DATE_TIME_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss:SSS");

}
Run Code Online (Sandbox Code Playgroud)

任何人都可以告诉我,如果我在其余的API中使用这种方式会遇到什么问题?
如果我将其用作实例变量,我最终将在多个类中对其进行声明?

java sonarqube sonarlint

3
推荐指数
2
解决办法
628
查看次数

IntelliJ Idea + Could not autowire. No beans of type found

I keep seeing below error in my IntelliJ Idea, however the code works fine during execution.

Could not autowire. No beans of 'PortfolioRequestHandler' type found. less... (Ctrl+F1) 
Inspection info:Checks autowiring problems in a bean class.
Run Code Online (Sandbox Code Playgroud)

Sample Code

@ActiveProfiles("test")
@RunWith(SpringRunner.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD)
@SpringBootTest(classes = {Application.class})
public class PortfolioRequestHandlerTest {

    @Autowired
    private PortfolioRequestHandler portfolioRequestHandler;

    ...
    ...
}
Run Code Online (Sandbox Code Playgroud)

How do I get rid of this? I am using IntelliJ Idea ULTIMATE 2018.2

intellij-idea spring-boot

3
推荐指数
1
解决办法
1万
查看次数

Spring Boot使用SSL证书连接数据库

我需要使用 Spring Boot 应用程序中的 SSL 证书连接到 postgresql。我已经获得了证书,目前我正在使用我在 application.yml 文件中提供的用户名和密码连接到数据库。

有人可以指出我正确的教程吗?我找不到与 spring boot ssl 数据库连接相关的任何内容。

postgresql ssl-certificate spring-boot

3
推荐指数
1
解决办法
4870
查看次数

map.foreach java8中的条件总和

public Double getUnitsBefore(Date recordDate) {
    double eligibleUnits = 0;
    ageBucket.forEach((dateStr, units) -> {
        try {
            Date date = DFT.parse(dateStr);
            if (date.before(recordDate)) {
                //TODO These are eligible units for dividend.
                eligibleUnits = eligibleUnits + units.doubleValue();    //TODO 
            }

        } catch(ParseException e) {
            e.printStackTrace();
        }
    });

    return eligibleUnits;
}
Run Code Online (Sandbox Code Playgroud)
  • 如您所知,行在eligibleUnits = eligibleUnits + units.doubleValue();Java 8 中无法编译。我如何实现这一目标?我只需要在日期在记录日期之前求和。

java java-8

2
推荐指数
1
解决办法
1357
查看次数

带有注释和缓存的 Spring Batch

有没有人有 Spring Batch (Using Annotation) 的好例子来缓存一个处理器可以访问的引用表?

我只需要一个简单的缓存,运行一个返回一些 byte[] 的查询并将其保存在内存中,直到时间作业执行。

感谢有关此主题的任何帮助。

谢谢 !

spring-batch spring-boot spring-cache

2
推荐指数
1
解决办法
3136
查看次数

java8 orElse(null.getValue())如何处理

elseCondition当前抛出空值时是否可以在一行中写nullPointer

在我的场景中,returnValue是一个String,它为null。

我要写的条件是

if (returnValue != null) {
    return returnValue;
} else if (elseCondition != null) {
    return elseCondition.getValue();
} else {
    return null;
}

Optional.ofNullable(returnValue).orElse(elseCondition.getValue()) //throws nullPointer as elseCondition is null

class ElseCodnition {
    private  String value;

    getValue() {...}
}
Run Code Online (Sandbox Code Playgroud)

java java-8

2
推荐指数
1
解决办法
92
查看次数

Java8 stream().map().reduce()实际上是map reduce

我在某处使用stream().map().reduce()看到了这段代码.

这个map()函数真的可以并行工作吗?如果是,那么它可以为map()函数启动多少个最大线程数?

如果我对下面的特定用例使用parallelStream()而不仅仅是stream(),该怎么办?

任何人都可以给我一个很好的例子,说明不使用parallelStream()的地方

下面的代码只是从tCode中提取tName并返回逗号分隔的String.

String ts = atList.stream().map(tcode -> {
    return CacheUtil.getTCache().getTInfo(tCode).getTName();
}).reduce((tName1, tName2) -> {
    return tName1 + ", " + tName2;
}).get();
Run Code Online (Sandbox Code Playgroud)

java java-8

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

无需用户身份验证的 SpringBoot IBM MQ

目前,我的 Spring Boot application.yaml 中有以下属性。

ibm:
   mq:
      queueManager: <queue-manager>
      channel: <channel>
      connName: <host>(<port>)
      queue: <queue-name>
      user: <user>
      password: <password>
Run Code Online (Sandbox Code Playgroud)

我想在没有密码的情况下进行连接,为此我必须设置jmsConnectionFactory.setBooleanProperty(WMQConstants.USER_AUTHENTICATION_MQCSP, false);属性。

无论如何,我可以通过将参数传递给 connName 在 application.yaml 中指定此属性吗?

在哪里可以找到与 IBM MQ 相关的所有预定义的关键 spring-boot 应用程序属性?

jms spring-boot ibm-mq

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

使用lamda时处理空指针

nullPointerException除非e.getKey()返回,否则以下代码将永远有效null

Map<Integer, Optional<SecurityAttributeChange>> spnCreationDetails;
Optional.ofNullable(spnCreationDetails.get(e.getKey()).orElse(new SecurityAttributeChange()).getNewAttribute())
                                    .orElse(new SecurityAttr())
                                    .getUserName());
Run Code Online (Sandbox Code Playgroud)

我在这一行中正在使用NPE,是否可以调试它?我知道spnCreationDetails.get(e.getKey())返回null,null在这里处理过程中我是否遗漏了什么?


-编辑


这是几乎完整的方法,将有助于提供有关如何重构它以便使其可读的输入。

private void updateAuditFields(List<SecurityAttributeChange> securityChanges, Map<Integer, Map<String, Object>> result) {

    Map<Integer, Optional<SecurityAttributeChange>> spnModificationDetails = ...

    Map<Integer, Optional<SecurityAttributeChange>> spnCreationDetails = ...

    result.entrySet().stream().forEach(e -> {
        e.getValue()
                .put("userIdLastChanged",
                        Optional.ofNullable(Optional.ofNullable(spnModificationDetails.get(e.getKey()))
                                .orElse(Optional.of(new SecurityAttributeChange()))
                                .get()
                                .getNewAttribute()).orElse(new SecurityAttr()).getUserName());

        e.getValue()
                .put("lastChangedDatetime",
                        Optional.ofNullable(Optional.ofNullable(spnModificationDetails.get(e.getKey()))
                                .orElse(Optional.of(new SecurityAttributeChange()))
                                .get()
                                .getNewAttribute()).orElse(new SecurityAttr()).getKnowledgeBeginDate());

        e.getValue()
                .put("userIdCreated", Optional.ofNullable(
                        Optional.ofNullable(spnCreationDetails.get(e.getKey())).orElse(Optional.of(new SecurityAttributeChange())).get().getNewAttribute())
                        .orElse(new SecurityAttr())
                        .getUserName());

        e.getValue()
                .put("createdDatetime",
                        Optional.ofNullable(Optional.ofNullable(spnCreationDetails.get(e.getKey()))
                                .orElse(Optional.of(new SecurityAttributeChange()))
                                .get()
                                .getNewAttribute()).orElse(new SecurityAttr()).getKnowledgeBeginDate());

    });
}
Run Code Online (Sandbox Code Playgroud)

java java-8

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

使用 Apache Camel 进行单元测试

我想在骆驼路线下面进行测试。我在网上找到的所有示例都有以文件开头的路由,在我的情况下,我有一个 spring bean 方法,它每隔几分钟就会被调用一次,最后消息被转换并移动到 jms 和审计目录。

我对这条路线的写测试知之甚少。我目前在我的测试用例中的所有内容是 Mockito.when(tradeService.searchTransaction()).thenReturn(dataWithSingleTransaction);

from("quartz2://tsTimer?cron=0/20+*+8-18+?+*+MON,TUE,WED,THU,FRI+*")
.bean(TradeService.class)
.marshal()
.jacksonxml(true)
.to("jms:queue:out-test")
.to("file:data/test/audit")
.end();
Run Code Online (Sandbox Code Playgroud)

apache-camel spring-boot-test

0
推荐指数
1
解决办法
3838
查看次数