SPRINGMVC in the controller injection request will be wired to the security issue? _spring

Source: Internet
Author: User
@Controller public
class acontroller{

    @Autowire
    httpservletrequest request;
    
    @RequestMapping ("/test") public result
    test () {
        System.out.println (request.tostring ());
        Request.getheader ("UID");
    }

For example, the above code,
After I use Autowire to inject request, I use request directly in the Controller method,
Since the controller default is a single example, I was wondering if there would be a thread security problem.
Because I output the hashcode of the request, the hashcode is the same every time.
Then whether the request will overwrite the current request causes the information to be distorted.

····························· Supplemental

1, I want to use HttpServletRequest in every method of controller, then every time in the method to declare I feel more trouble. I don't know how we can solve the problem.
2. The reason I write this is that I want to use the request as a member variable of the parent class by inheriting a parent class, which can be used directly in the method.
3, I through the downstairs Fork Brother Way (before that is written)

Public result test (HttpServletRequest request) {

    System.out.println (request.tostring ());
}

It is also constantly accessed, or accessed with different clients. Discover that the hashcode of each request that is printed is actually the same, why.


This writing is thread safe for the following reasons: the request injected in controller is the JDK dynamic proxy object, instance of Objectfactorydelegatinginvocationhandler. When we call the member domain request method, we actually invoke the Objectfactory GetObject () Object. The objectfactory here is requestobjectfactory. The GetObject of Requestobjectfactory is actually taken from the threadlocal of Requestcontextholder. Requests have just entered the SPRINGMVC Dispatcherservlet will be the request related objects set to Requestcontextholder threadlocal.

Reference: Inject the request member field into the SPRINGMVC controller

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.