mercredi 24 novembre 2021

Component of web-aware scopes are not created during app initialization

I'm using springBootVersion = '2.5.4' and trying to autowire the following component:

@Component
@RequestScope
public class TokenDecodingService {
   
   @Autowired
   HttpServletRequest httpServletRequest;
/* Some logic with request */
}

into my controller

@RestController
@Slf4j
//@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class DrupalEnhancedController {

    @Autowired
    TokenDecodingService tokenDecodingService;

    ....

}

During debugging I see that I get No Scope registered for scope name 'request' exception. The same problem goes for each web-aware scope.

First, I thought that I was using the wrong application context, but I've figured out that I'm using AnnotationConfigReactiveWebServerApplicationContext and this context should accept web-aware scopes of beans/components.

Also I tried to define this logic inside a bean like this:

    @Bean
    @RequestScope
    public TokenDecodingService tokenDecodingService() {
        return new TokenDecodingService();
    }

and tried to define context listener manually:

@Bean 
public RequestContextListener requestContextListener(){
    return new RequestContextListener();
}

But unfortunatelly I didn't make any progress this way. I think that the root cause here is the absence of web-aware contexts, so how can I enable them?




Aucun commentaire:

Enregistrer un commentaire