简体   繁体   中英

How to get an object in spring boot from REQUEST scope

How to get an object in Spring Boot from REQUEST scope in several classes (without forwarding to classes). Those. it is necessary in each class to have an actual object for the current request. If possible.

@Bean(name = "wp")
@Scope(value = WebApplicationContext.SCOPE_REQUEST, proxyMode = ScopedProxyMode.TARGET_CLASS)
public WrapperRequest getWrapperRequest() {
    WrapperRequest wrapperRequest = new WrapperRequest();
    wrapperRequest.setJdbcTemplate(jdbcTemplate);
    return wrapperRequest;
}

You can @Autowired it in a class under spring context ( For example class with @Component , @Service , @Repository annotation)

Example:

@Autowired
private WrapperRequest wp;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM