我创建了示例Spring-boot应用程序,它运行正常,没有任何错误,
现在我想练习spring-retry重试一些方法。如果我不使用,@EnableRetry我的应用程序启动时将没有任何错误,但重试无法正常进行。
如果我@EnableRetry在配置类上使用,我的应用程序无法启动
build.gradle
apply plugin: 'java-library'
repositories {
jcenter()
}
dependencies {
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.1.0.RELEASE'
// https://mvnrepository.com/artifact/org.springframework.kafka/spring-kafka
compile group: 'org.springframework.kafka', name: 'spring-kafka', version: '2.2.0.RELEASE'
// https://mvnrepository.com/artifact/commons-logging/commons-logging
compile group: 'commons-logging', name: 'commons-logging', version: '1.2'
// https://mvnrepository.com/artifact/org.springframework.retry/spring-retry
compile group: 'org.springframework.retry', name: 'spring-retry', version: '1.2.0.RELEASE'
}
Run Code Online (Sandbox Code Playgroud)
设定档
import org.springframework.context.annotation.Configuration;
import org.springframework.retry.annotation.EnableRetry;
@Configuration
@EnableRetry
public class RetryConfig {
}
Run Code Online (Sandbox Code Playgroud)
重试服务
@Service
public class RetryService {
@Retryable(value = { CustomException.class …Run Code Online (Sandbox Code Playgroud) 我正在开发 spring boot 2 应用程序,并尝试通过配置 hikari 数据源和 spring Jpa 与 postgresql 数据库建立连接。
我在这方面取得了成功,并且我正在使用hibernate.hbm2ddl.autoas update,因此它会在不存在的情况下创建表,但唯一的问题是当架构不存在时它会引发异常
错误
GenerationTarget encountered exception accepting command : Error executing DDL via JDBC Statement
Caused by: org.postgresql.util.PSQLException: ERROR: schema "test_schema" does not exist
Run Code Online (Sandbox Code Playgroud)
我通过配置类手动配置了一切
配置类
@Bean
@Primary
public HikariDataSource dataSource() {
HikariConfig config = new HikariConfig();
config.setJdbcUrl(databaseUrl);
config.setUsername(username);
config.setPassword(password);
config.setDriverClassName(driverClassName);
config.setConnectionTimeout(connectionTimeout);
config.setIdleTimeout(idleTimeout);
config.setMaximumPoolSize(maxpoolSize);
config.setMaxLifetime(maxLifeTime);
config.setMinimumIdle(minIdleConnections);
//config.setPoolName(poolName);
return new HikariDataSource(config);
}
@Bean
public Properties additionalProps() {
Properties jpaProps = new Properties();
jpaProps.put(hbDialect, "org.hibernate.dialect.PostgreSQLDialect");
jpaProps.put(autoDDL, "update"); …Run Code Online (Sandbox Code Playgroud) 我希望有一个函数返回我给它的参数的多个结果函数。
我已经尝试过谷歌搜索等,但没有任何运气
例如:
def function(x, i_add = False):
if i_add == True:
y = x+1
return x, (Y)?
Run Code Online (Sandbox Code Playgroud)
给出的例子我想要的结果是:
function(3) -> 3
function(3, True) -> 3, 4
function(3, False) -> 3
Run Code Online (Sandbox Code Playgroud)
我正在使用 python 2.7
仅供参考:我发誓没有激活配置文件配置,例如 -D 或运行配置
\n\n当应用程序在没有任何激活配置文件的情况下启动时,dev配置文件将默认激活。
我已经设置了spring.profile.default = dev,并且我希望开发配置文件被激活。但事实并非如此。
Run Environment
Spring-Boot-版本:2.1.2 发布
\n\nWhat I\'m referred
1) 如何在 Spring Boot 应用程序中使用配置文件 - \n https://www.javacodegeeks.com/2019/07/profiles-spring-boot-application.html#respond
\n\n这是我所做的代码
\n\n/resources/application.properties
spring.profiles.default= dev\n\napplication.environment=This is a "Default" Environment\nRun Code Online (Sandbox Code Playgroud)\n\n/resources/application-dev.properties
application.environment=This is a "dev" Environment\nserver.port= 8082\nRun Code Online (Sandbox Code Playgroud)\n\n/ProfileController.java
@RestController\n@RequestMapping("/v1")\npublic class ProfileController {\n\n @Value("${application.environment}")\n private String applicationEnv;\n\n @GetMapping\n public String getApplicationEnv(){\n return applicationEnv;\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n\nlocalhost/v1 …
假设我们有一个名为的主题Topic和一个CG包含三个消费者的消费者组。组偏移等于 0。
消费者开始阅读消息。
读取顺序:
问题是:消息 1 会发生什么?
或者也许我错误地理解了消费者如何阅读消息,因为我是 Kafka 的新手。
版本:Apache Kafka 2.4.0
我正在尝试使mockMvc 调用与wiremock 一起运行。但是代码中下面的mockMvc调用不断抛出404而不是预期的200 HTTP状态代码。
我知道wiremock正在运行..当wiremock运行时我可以通过浏览器执行http://localhost:8070/lala 。
有人可以建议吗?
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestApp.class)
@AutoConfigureMockMvc
public class MyControllerTest {
@Inject
public MockMvc mockMvc;
@ClassRule
public static final WireMockClassRule wireMockRule = new WireMockClassRule(8070);
@Rule
public WireMockClassRule instanceRule = wireMockRule;
public ResponseDefinitionBuilder responseBuilder(HttpStatus httpStatus) {
return aResponse()
.withStatus(httpStatus.value());
}
@Test
public void testOne() throws Exception {
stubFor(WireMock
.request(HttpMethod.GET.name(), urlPathMatching("/lala"))
.willReturn(responseBuilder(HttpStatus.OK)));
Thread.sleep(1000000);
mockMvc.perform(MockMvcRequestBuilders.request(HttpMethod.GET, "/lala")) .andExpect(status().isOk());
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个即时日期,例如:2020-03-09T20:13:57.089Z并且我想在即时中找到第二天的结束时间,例如 - 2020-03-10T23:59:59.089Z(这将是与初始日期相比的第二天的结束时间)
如何使用 Java 中的 Instant 来做到这一点?
我想知道流(或收集器)中是否已经实现了一个功能,它首先按属性对流进行分组,然后返回按另一个属性排序的列表中的第一个元素。例如,以下代码尝试使用第一个属性对对象流进行分组,然后想要收集具有第二个属性的最高值的对象。
class MyClass{
String att1;
String att2;
}
Run Code Online (Sandbox Code Playgroud)
现在,我想用 Stream myClassStream 来实现这样的东西 -
Map<String,MyClass> myMap = myClassStream().collect(Collectors.groupingBy(MyClass::getAtt1)); //Now I want to do Sorting after grouping to collect only the element which has the highest value of attr2.
Run Code Online (Sandbox Code Playgroud)
我使用简单 for 循环的代码是:
Map<String, MyClass> postAnalyticsMap = new HashMap<>();
for (MyClass post : myClassList) {
if (post.get(post.getAtt1()) == null) {
post.put(post.getAtt1(), post);
} else {
MyClass existingClass = postAnalyticsMap.get(post.getAtt1());
if (existingPostAnalytics.getAtt2() < post.getAtt2()) {
postAnalyticsMap.put(post.getAtt1(), post);
}
}
}
Run Code Online (Sandbox Code Playgroud)
任何帮助都感激不尽。
我有以下代码:
private val parsed = ObjectMapper().readTree(vcap)
parsed.get("spaces")?.firstOrNull()?.get("block1")?.asText()
Run Code Online (Sandbox Code Playgroud)
我想使用点符号进行导航(出于可读性原因)。就像是:
private val parsed = ObjectMapper().readTree(vcap)
parsed.get("spaces[0].block1")?.asText()
Run Code Online (Sandbox Code Playgroud)
是否可以?
我想从 application.properties 获取值。
@ExtendWith(MockitoExtension.class)
public class CurrencyServiceTest {
@Mock
private OpenExchangeRatesClient openExchangeRatesClient;
@Value("${openexchangerates.app.id}")
private String appId;
@Value("${openexchangerates.currency.base}")
private String base;
...
Run Code Online (Sandbox Code Playgroud)
问题是 appId 和 base 在测试中为 null。这是什么原因呢?
java ×8
spring-boot ×5
spring ×2
apache-kafka ×1
aspectj ×1
date ×1
function ×1
hibernate ×1
jackson ×1
java-8 ×1
java-stream ×1
java-time ×1
json ×1
kotlin ×1
mockito ×1
postgresql ×1
python ×1
return ×1
spring-retry ×1
testing ×1
time ×1
wiremock ×1