-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Closed as not planned
Labels
for: stackoverflowA question that's better suited to stackoverflow.comA question that's better suited to stackoverflow.com
Description
I defined a bean configuration class:
@Configuration
public class CoreAppBeanConfiguration {
@Bean
@Scope(value = WebApplicationContext.SCOPE_REQUEST, proxyMode = ScopedProxyMode.TARGET_CLASS)
public CoreAppContext getCoreAppContext() {
CoreAppContext context = new CoreAppContext();
return context;
}
}Then I defined a filter to initialize the CoreAppContext:
@Provider
@Component
public class TestHandler implements ContainerRequestFilter, ContainerResponseFilter {
@Autowired
private CoreAppContext coreAppContext;
@Override
public void filter(ContainerRequestContext containerRequestContext) throws IOException {
coreAppContext.id="1";
coreAppContext.name="test";
RequestContextHolder.currentRequestAttributes().setAttribute("coreAppContext", coreAppContext, RequestAttributes.SCOPE_REQUEST);
}
}Finally I defined a resource class to get the CoreAppContext value:
@Path("/test")
public class TestResource {
@GET
@Path("/get")
public String get() {
CoreAppContext coreAppContext= (CoreAppContext) RequestContextHolder.getRequestAttributes().getAttribute("coreAppContext", 0);
String result = coreAppContext.getIdName();
return result;
}
}Metadata
Metadata
Assignees
Labels
for: stackoverflowA question that's better suited to stackoverflow.comA question that's better suited to stackoverflow.com


