我有一个休息的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中使用这种方式会遇到什么问题?
如果我将其用作实例变量,我最终将在多个类中对其进行声明?
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
我需要使用 Spring Boot 应用程序中的 SSL 证书连接到 postgresql。我已经获得了证书,目前我正在使用我在 application.yml 文件中提供的用户名和密码连接到数据库。
有人可以指出我正确的教程吗?我找不到与 spring boot ssl 数据库连接相关的任何内容。
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 中无法编译。我如何实现这一目标?我只需要在日期在记录日期之前求和。有没有人有 Spring Batch (Using Annotation) 的好例子来缓存一个处理器可以访问的引用表?
我只需要一个简单的缓存,运行一个返回一些 byte[] 的查询并将其保存在内存中,直到时间作业执行。
感谢有关此主题的任何帮助。
谢谢 !
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) 我在某处使用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) 目前,我的 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 应用程序属性?
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) 我想在骆驼路线下面进行测试。我在网上找到的所有示例都有以文件开头的路由,在我的情况下,我有一个 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) java ×5
java-8 ×4
spring-boot ×4
apache-camel ×1
ibm-mq ×1
jms ×1
postgresql ×1
sonarlint ×1
sonarqube ×1
spring-batch ×1
spring-cache ×1