相关疑难解决方法(0)

使用两个端口配置Spring Boot

我正在尝试使用两个不同的端口在Spring Boot中配置应用程序,但我还没有.我的第一个aproximation是两个控制器,我在两个控制器中用container.setPort(8080)定义了一个@Bean; 我的第二个aproximation已经添加了执行器依赖并改变了管理的端口,但我的应用程序没有运行."地址已在使用中:绑定",如何使用两个端口来配置应用程序?我想要一个端口用于管理员,另一个端口用于我的api的咨询.

spring spring-boot spring-boot-actuator

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

在非 Web Spring Boot 应用程序中自动配置 ClientRegistrationRepository

我正在使用 Spring Boot 2.7.1 和spring-boot-starter-batch. 该批处理需要 2 个不同的WebClientAPI 来调用具有不同身份验证系统的 2 个不同的 API,我通过标准 Spring Boot 属性(spring.security.oauth2.client 等)进行配置。

它运行良好,但我意识到批处理在运行时正在侦听端口 8080,因为我已经导入了spring-boot-starter-web,这可以WebClient通过注入ClientRegistrationRepository. 这不是一个主要问题,但它阻止我并行启动批处理两次,因为端口已被使用......所以我想禁用网络服务器部分。

问题是,当我通过属性、代码或依赖项(通过删除spring-boot-starter-web)禁用网络服务器时,批处理不再启动,因为ClientRegistrationRepository不再加载,因为我需要

a bean of type 'org.springframework.security.oauth2.client.registration.ClientRegistrationRepository' that could not be found
Run Code Online (Sandbox Code Playgroud)

这是因为 Spring 有一个条件OAuth2ClientAutoConfiguration

@AutoConfiguration(before = SecurityAutoConfiguration.class)
@ConditionalOnClass({ EnableWebSecurity.class, ClientRegistration.class })
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
@Import({ OAuth2ClientRegistrationRepositoryConfiguration.class, OAuth2WebSecurityConfiguration.class })
public class OAuth2ClientAutoConfiguration {

}
Run Code Online (Sandbox Code Playgroud)

由于应用程序的类型不是SERVLET, but NONE,因此不会启用此功能。

我尝试过“强制加载”它:

@ImportAutoConfiguration(OAuth2ClientAutoConfiguration.class)
Run Code Online (Sandbox Code Playgroud)

但它不起作用。

查看源代码,我发现OAuth2ClientAutoConfiguration实际上加载了 …

java spring-boot

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

标签 统计

spring-boot ×2

java ×1

spring ×1

spring-boot-actuator ×1