如果我有以下配置:
<defaultCache timeToIdleSeconds="120"
timeToLiveSeconds="120" />
<cache name="test"
timeToLiveSeconds="300" />
Run Code Online (Sandbox Code Playgroud)
timeToIdleSeconds缓存的价值是test什么?它是继承自默认缓存,因此等于120,还是采用手册中给出的默认值,即0(无穷大)?
使用Spring Boot 1.4和Logback,我在以下位置配置日志记录application.yml:
logging:
level:
org.hibernate.SQL: INFO
com.netflix.eureka: OFF
Run Code Online (Sandbox Code Playgroud)
请注意,第二个配置的建议直接来自Spring Cloud Service Registration and Discovery文档.它对INFO和其他"正常"级别非常有效.但是,日志还显示(由我重新格式化):
… o.s.cloud.logging.LoggingRebinder : Cannot set level: false for
'org.hibernate.engine.internal.StatisticalLoggingSessionEventListener'
Run Code Online (Sandbox Code Playgroud)
现在,false是一个非常有趣的水平,不是吗?如何完全禁用记录器?
我有一个设置名称并在拉取请求上运行的 Github 操作:
\nname: Code Quality\non:\n workflow_dispatch:\n pull_request:\n branches: [ main, develop ]\nRun Code Online (Sandbox Code Playgroud)\n当我手动触发运行时(因为workflow_dispatch也设置了),运行将在运行列表中获得标题 \xe2\x80\x9cCode Quality\xe2\x80\x9d 。
但是,当针对拉取请求运行该操作时,列表中的运行名称将设置为 PR 的名称。这可能是也可能不是一个好标题,很大程度上取决于 PR\xe2\x80\x99s 作者。有没有办法影响列表中操作的标题?
\n我有阵列 var john = ['asas','gggg','ggg'];
如果我john在索引3处访问,即.john[3], 它失败.
如何显示消息或警告,说明该索引没有值?
在JaCoCo生成的Maven站点报告中,由于我所有已编译的JSP都包含在内(并且它们很长),因此我的报道非常糟糕.我尝试了以下内容reporting:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<exclude>target/classes/jsp/**/*.class</exclude>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
另一个外观相似的配置在buildPOM的prepare-package相位部分.这并不能阻止JSP类包含在报告中.怎么避免呢?
我使用Sonarqube 5.1并尝试使用"Sonar way"Java质量配置文件.工作很简单:我想为缺少的媒体类型定义一个全局 String常量:
public interface Utf8MediaType {
String APPLICATION_JSON = "application/json;charset=UTF-8";
}
Run Code Online (Sandbox Code Playgroud)
然而,Sonarqube告诉我这在规则squid中是不好的做法:S1214 - 不应在接口中定义常量.长篇文章讨论了实现这个接口,我并不打算这样做,但我放弃并创建了一个类:
public class Utf8MediaType {
public static final String APPLICATION_JSON = "application/json;charset=UTF-8";
}
Run Code Online (Sandbox Code Playgroud)
但是,这被认为是规则squid中的一个主要设计问题:S1118 - 实用程序类不应该有公共构造函数.所以它敦促我添加一个私有构造函数.当然,这个构造函数首先不要违反规则squid中的约定:S1213 - 接口声明或类的成员应该以预定义的顺序出现.我想在那之后我甚至可能会得到common-java:InsufficientBranchCoverage,因为私有构造函数不在测试中.
这些是默认规则,我觉得它们组合起来有点傻.我有更多的例子,其中默认值对我们不起作用(缺少TestNG支持).我能做些什么呢?您有什么推荐的吗?
我正在将一些测试从Hamcrest转换为AssertJ.在Hamcrest中,我使用以下代码段:
assertThat(list, either(contains(Tags.SWEETS, Tags.HIGH))
.or(contains(Tags.SOUPS, Tags.RED)));
Run Code Online (Sandbox Code Playgroud)
也就是说,列表可以是那个或那个.我如何在AssertJ中表达这一点?该anyOf功能(当然,任何别的东西比任何,但是这将是第二个问题)需要Condition; 我已经实现了这一点,但感觉好像这应该是一个常见的情况.
这个问题已经过时了.
org.apache.commons:commmons-lang3:3.7删除了已弃用的标志,并确认了3.8.
更新后org.apache.commons:commons-lang3:3.6,3.5我得到许多关于RandomStringUtils被弃用的警告.建议的替代方案RandomStringGenerator来自commons-text.但是,如果您想要的只是一个字符串(例如,在单元测试中),那么该类非常笨拙.相比:
String name1 = RandomStringUtils.randomAlphabetic(FIRST_NAME_LENGTH);
String name2 = new RandomStringGenerator.Builder().withinRange('a', 'z').build()
.generate(FIRST_NAME_LENGTH);
Run Code Online (Sandbox Code Playgroud)
(我知道这甚至不是相同的语义,但想要保持简短.)
所以我正在寻找一种简短而优雅的方式,理想情况下是直接替换; Java 8,Spring,Guava甚至只测试库都是受欢迎的.
我在SpringBoot项目中使用@SneakyThrows Lombok功能.当CGLIB代理实现它抛出java.lang.Exception时,我遇到此功能的问题
:预期的异常,但是<java.lang.reflect.UndeclaredThrowableException>.
它可以以某种方式修复吗?
提供示例.
有接口和两个实现.
public interface SneakyThrowsExample {
void testSneakyThrows();
}
Run Code Online (Sandbox Code Playgroud)
简单的实施
import lombok.SneakyThrows;
import org.springframework.stereotype.Component;
import java.io.IOException;
@Component(value = "simpleSneakyThrowsExample")
public class SimpleSneakyThrowsExample implements SneakyThrowsExample {
@Override
@SneakyThrows
public void testSneakyThrows() {
throw new IOException();
}
}
Run Code Online (Sandbox Code Playgroud)
和@Transactional实现.CGLIB将代理此实现.
import lombok.SneakyThrows;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.io.IOException;
@Component(value = "transactionalSneakyThrowsExample")
public class TransactionalSneakyThrowsExample implements SneakyThrowsExample {
@Override
@SneakyThrows
@Transactional
public void testSneakyThrows() {
throw new IOException();
}
}
Run Code Online (Sandbox Code Playgroud)
创建@SpringBootTest测试并注入这两个实现 …
The Console Launcher that comes with JUnit Platform (from JUnit 5) produces a quite nice summary view at the end. The Maven Surefire plugin, however, has a very simple output.
Is it possible to create with Surefire output similar to what the launches creates?