在我的生产代码中,当 Mono 超时时,我的日志中出现错误。
我已设法使用以下代码重新创建这些错误:
@Test
public void testScheduler() {
Mono<String> callableMethod1 = callableMethod();
callableMethod1.block();
Mono<String> callableMethod2 = callableMethod();
callableMethod2.block();
}
private Mono<String> callableMethod() {
return Mono.fromCallable(() -> {
Thread.sleep(60);
return "Success";
})
.subscribeOn(Schedulers.elastic())
.timeout(Duration.ofMillis(50))
.onErrorResume(throwable -> Mono.just("Timeout"));
}
Run Code Online (Sandbox Code Playgroud)
在Mono.fromCallable我正在使用第三方库进行阻塞调用。当此调用超时时,我收到类似于
reactor.core.publisher.Operators - Operator called default onErrorDropped
reactor.core.publisher.Operators - Scheduler worker in group main failed with an uncaught exception
Run Code Online (Sandbox Code Playgroud)
这些错误似乎也是间歇性的,有时当我运行代码时,我根本没有得到任何错误。但是,当我以 10 的循环重复调用时,我始终得到它们。
我已更新后端服务以使用最新的 Spring Boot 3,但是更新后,SB 应用程序由于在配置加载期间设置延迟日志的一些问题而失败。任何人都可以帮忙想想可能出了什么问题,下面是堆栈跟踪:
java.lang.IllegalArgumentException: Unable to instantiate factory class [org.springframework.cloud.config.client.ConfigServerConfigDataLocationResolver] for factory type [org.springframework.boot.context.config.ConfigDataLocationResolver]
at org.springframework.core.io.support.SpringFactoriesLoader$FailureHandler.lambda$throwing$0(SpringFactoriesLoader.java:650)
at org.springframework.core.io.support.SpringFactoriesLoader$FailureHandler.lambda$handleMessage$3(SpringFactoriesLoader.java:674)
at org.springframework.core.io.support.SpringFactoriesLoader.instantiateFactory(SpringFactoriesLoader.java:231)
at org.springframework.core.io.support.SpringFactoriesLoader.load(SpringFactoriesLoader.java:206)
at org.springframework.core.io.support.SpringFactoriesLoader.load(SpringFactoriesLoader.java:160)
at org.springframework.boot.context.config.ConfigDataLocationResolvers.<init>(ConfigDataLocationResolvers.java:66)
at org.springframework.boot.context.config.ConfigDataEnvironment.createConfigDataLocationResolvers(ConfigDataEnvironment.java:160)
at org.springframework.boot.context.config.ConfigDataEnvironment.<init>(ConfigDataEnvironment.java:148)
at org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor.getConfigDataEnvironment(ConfigDataEnvironmentPostProcessor.java:101)
at org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor.postProcessEnvironment(ConfigDataEnvironmentPostProcessor.java:96)
at org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor.postProcessEnvironment(ConfigDataEnvironmentPostProcessor.java:89)
at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEnvironmentPreparedEvent(EnvironmentPostProcessorApplicationListener.java:109)
at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEvent(EnvironmentPostProcessorApplicationListener.java:94)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131)
at org.springframework.boot.context.event.EventPublishingRunListener.multicastInitialEvent(EventPublishingRunListener.java:136)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:81)
at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:64)
at java.base/java.lang.Iterable.forEach(Iterable.java:75)
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:118)
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:112)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:63)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:352)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
at org.springframework.boot.test.context.SpringBootContextLoader.lambda$loadContext$3(SpringBootContextLoader.java:137)
at org.springframework.util.function.ThrowingSupplier.get(ThrowingSupplier.java:59)
at org.springframework.util.function.ThrowingSupplier.get(ThrowingSupplier.java:47)
at org.springframework.boot.SpringApplication.withHook(SpringApplication.java:1386)
at org.springframework.boot.test.context.SpringBootContextLoader$ContextLoaderHook.run(SpringBootContextLoader.java:543)
at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:137) …Run Code Online (Sandbox Code Playgroud) 当我使用 Spring Boot 2.7.2 时,一切正常。升级到版本 3.0.0-SNAPSHOT 后,我有
我的pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.0-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>spring_jwt</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>spring-boot-security-jwt</name>
<description>spring_jwt</description>
<properties>
<java.version>18</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-api</artifactId>
<version>0.11.5</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-impl</artifactId>
<version>0.11.5</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-jackson</artifactId>
<version>0.11.5</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId> …Run Code Online (Sandbox Code Playgroud) 我刚刚开始一个基于Spring boot 2 + Webflux的新项目.在升级版本的spring boot并替换spring-boot-starter-web为spring-boot-starter-webflux类
缺失.我现在如何配置defaultLocale和拦截器来改变语言?
我有返回的函数,Mono<Boolean>我想将它映射到Mono<Void>(因为这是我在Controller方法中返回的东西).
有没有更好的方法来返回这样的Mono而不是.flatMap { Mono.empty<Void>() }?
我无法使用.map{ null }因为映射功能无法接受nulls.
Spring Boot 3 将于 2022 年 11 月发布。候选版本 2 已经发布。
Spring Boot 3 将随 Spring AOT 一起发布。Spring AOT 生成额外的源代码,以便避免反射调用。
引入 Spring AOT 来生成GraalVM Native Images。然而,理论上 Spring AOT 也可以用于常规 JVM 应用程序,以加快启动过程(因为常规调用应该比反射调用更快)。
不幸的是,我在Spring Boot 3 参考文档中没有找到任何有关如何将 Spring AOT 用于常规 JVM 应用程序的内容。你知道我如何在常规 JVM 应用程序中从 Spring AOT 中获益吗?
我创建了一个如下所示的RestController:
@RestController
public class GreetingController {
@RequestMapping(value = "/greetings", method = RequestMethod.GET)
public Mono<Greeting> greeting(HttpServletRequest request) {
return Mono.just(new Greeting("Hello..." + request.toString()));
}
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,当我尝试点击"问候"端点时,我得到一个例外:
java.lang.IllegalStateException:没有类型为[org.apache.catalina.servlet4preview.http.HttpServletRequest]的参数[0]的解析器
我在用
Run Code Online (Sandbox Code Playgroud)compile('org.springframework.boot.experimental:spring-boot-starter-web-reactive')
如何解决这个问题?
- - - - - 编辑 - - - - -
使用界面.现在得到:
java.lang.IllegalStateException:方法上没有[javax.servlet.http.HttpServletRequest]类型的参数[0]的解析器(其余相同)
我们正在使用Spring Boot 1.5.9中的下一个接口,工作没有任何问题:ConfigurableEmbeddedServletContainer和EmbeddedServletContainerCustomizer.
我们已升级到Spring Boot 2(2.0.0.M7),这些接口不存在.我们认为它们已针对具有相同目的的其他接口进行了修改,但我们不知道它们是什么.
有人可以帮助我们知道如何修改这段代码以获得与Spring 1.5.9中相同的行为吗?
我们的代码是下一个:
@Bean
public EmbeddedServletContainerCustomizer containerCustomizer() throws FileNotFoundException {
final TomcatConnectorCustomizer customizer = new MyTomcatConnectionCustomizer(absoluteKeystoreFile,
keystoreType, keystorePassword);
return new EmbeddedServletContainerCustomizer() {
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
if (container instanceof TomcatEmbeddedServletContainerFactory) {
TomcatEmbeddedServletContainerFactory containerFactory = (TomcatEmbeddedServletContainerFactory) container;
containerFactory.addConnectorCustomizers(customizer);
Connector connector = new Connector(TomcatEmbeddedServletContainerFactory.DEFAULT_PROTOCOL);
connector.setPort(port);
containerFactory.addAdditionalTomcatConnectors(connector);
}
}
};
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试将Spring boot 1.5应用程序移植到Spring Boot 2
现在我无法获得OAuth2访问令牌.
这是我成功使用Spring Boot 1.5的代码:
public static String loginAndGetAccessToken(String username, String password, int port) {
ResourceOwnerPasswordResourceDetails resourceDetails = new ResourceOwnerPasswordResourceDetails();
resourceDetails.setUsername(username);
resourceDetails.setPassword(password);
resourceDetails.setAccessTokenUri(String.format("http://localhost:%d/api/oauth/token", port));
resourceDetails.setClientId("clientapp");
resourceDetails.setClientSecret("123456");
resourceDetails.setGrantType("password");
resourceDetails.setScope(Arrays.asList("read", "write"));
DefaultOAuth2ClientContext clientContext = new DefaultOAuth2ClientContext();
OAuth2RestTemplate restTemplate = new OAuth2RestTemplate(resourceDetails, clientContext);
restTemplate.setMessageConverters(Arrays.asList(new MappingJackson2HttpMessageConverter()));
return restTemplate.getAccessToken().toString();
}
Run Code Online (Sandbox Code Playgroud)
它失败并出现以下异常:
java.lang.IllegalStateException: An OAuth 2 access token must be obtained or an exception thrown.
at org.springframework.security.oauth2.client.token.AccessTokenProviderChain.obtainAccessToken(AccessTokenProviderChain.java:124)
at org.springframework.security.oauth2.client.OAuth2RestTemplate.acquireAccessToken(OAuth2RestTemplate.java:221)
at org.springframework.security.oauth2.client.OAuth2RestTemplate.getAccessToken(OAuth2RestTemplate.java:173)
Run Code Online (Sandbox Code Playgroud)
看起来http://localhost:%d/api/oauth/token端点现在是安全的,无法访问
这是我的配置:
OAuth2ServerConfig
@Configuration
public class OAuth2ServerConfig {
public …Run Code Online (Sandbox Code Playgroud) 我正在将我的一个微服务迁移到Spring Boot 2.0.0.M6,并且--spring.config.location=在命令行上使用该选项时出现错误.错误如下:
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'property' in value "${property}"
at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:172) ~[spring-core-5.0.1.RELEASE.jar:5.0.1.RELEASE]
at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:124) ~[spring-core-5.0.1.RELEASE.jar:5.0.1.RELEASE]
at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:237) ~[spring-core-5.0.1.RELEASE.jar:5.0.1.RELEASE]
at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:211) ~[spring-core-5.0.1.RELEASE.jar:5.0.1.RELEASE]
at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.lambda$processProperties$0(PropertySourcesPlaceholderConfigurer.java:175) ~[spring-context-5.0.1.RELEASE.jar:5.0.1.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveEmbeddedValue(AbstractBeanFactory.java:834) ~[spring-beans-5.0.1.RELEASE.jar:5.0.1.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1081) ~[spring-beans-5.0.1.RELEASE.jar:5.0.1.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1060) ~[spring-beans-5.0.1.RELEASE.jar:5.0.1.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:578) ~[spring-beans-5.0.1.RELEASE.jar:5.0.1.RELEASE]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:91) ~[spring-beans-5.0.1.RELEASE.jar:5.0.1.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:367) ~[spring-beans-5.0.1.RELEASE.jar:5.0.1.RELEASE]
... 50 common frames omitted
Run Code Online (Sandbox Code Playgroud)
如果我不使用自定义属性文件,一切都按预期工作或使用RELEASE版本.我正在使用以下命令启动应用程序:
java -jar application.jar --spring.config.location=app.properties
我注意到当使用这个选项时,Spring完全替换了项目中的默认application.properties,不同于以前只是覆盖参数文件中的属性的Spring版本.这是一个错误吗?
得到了团队的回应,显然这是预期的行为.试着现在知道是否有办法使用旧版本的行为.
spring ×7
spring-boot ×7
java ×3
spring-mvc ×2
jpa ×1
kotlin ×1
logging ×1
spring-cloud ×1
thymeleaf ×1