Spring 为两个不同的入口点创建bean
我有一个使用spring boot运行的web应用程序。有一个服务应该能够由两个不同的端点触发。当前,端点仅由rest触发。在每次调用时,都应该创建一个POJO,其中包含关于调用方的元信息。服务使用此对象记录一些信息Spring 为两个不同的入口点创建bean,spring,spring-boot,spring-mvc,request,javabeans,Spring,Spring Boot,Spring Mvc,Request,Javabeans,我有一个使用spring boot运行的web应用程序。有一个服务应该能够由两个不同的端点触发。当前,端点仅由rest触发。在每次调用时,都应该创建一个POJO,其中包含关于调用方的元信息。服务使用此对象记录一些信息 @Configuration public class MetaInformationConfiguration { @Bean @Qualifier("MetaInformation") @Scope(scopeName = WebApplicationCo
@Configuration
public class MetaInformationConfiguration {
@Bean
@Qualifier("MetaInformation")
@Scope(scopeName = WebApplicationContext.SCOPE_REQUEST, proxyMode = ScopedProxyMode.TARGET_CLASS)
public @NonNull MetaInformation configure() {
// do something with the webcontext
}
}
这个很好用。但是现在我有了第二个调用者,他不通过rest使用端点。基础服务由时间触发器调用。在本例中,我遇到了一个错误,因为无法创建服务中使用的元信息,因为bean仅在http调用请求中可用
如果调用方不使用我的rest端点,我如何创建bean