Problems arising from the use of Spring-service in the filter for permission reasons

Source: Internet
Author: User


Load Order

Filter using injected bean

1. The project Spring uses the annotation method : In the filter debug see source, type

Allbeannamesbytype concurrenthashmap<k,v> (id=169) , there is the desired roleservice, but in the following code is not to be taken. General Report Exception:

Org.springframework.beans.factory.NoSuchBeanDefinitionException:No Bean named 'rolemanageservice' is Defined

Webapplicationcontext AC = webapplicationcontextutils. Getwebapplicationcontext (Request.getservletcontext ());

rolemanageservice rolemanageservice = (rolemanageservice) ac.getbean ("Rolemanageservice");

2. Try to use the various interfaces on the Internet:

Implementing the Applicationcontextaware Interface

extends Contextloaderlistener implements Servletcontextlistener

Wait, or you can't get the bean instance

3. Finally try to change this rolemanageservice to the XML configuration, finally in the filter to obtain, or use 1. method, observe the following two debug

<bean id= "Rolemanageservice" class= "Com.ljq.service.RoleManageService" > <property name= "Rolemanagedao" > <ref bean= "Rolemanagedao"/> </property></bean>

Figure 1

Figure 2

Figure 1 is the use of annotations,Allbeannamesbytype, there are instances of role, the constructor does not have role instances, getbean the time to get exceptions.

Figure 2 is a way of using XML configuration, There are instances of role in Allbeannamesbytype, constructors have role instances, andGetbean are normal.

4. For the above reasons, I think it should be in the Web loading order,

The spring container is annotated in such a way that it does not get a report exception after the filter .

The XML configuration of the spring container is preceded by the filter , so it can be obtained.

So. Change these instances to be used in the filter to the XML configuration method, and the others are annotated

But I refer to other people's articles, why can someone get an example of the annotation in the filter? Eh, only vegetables learn shallow good depressed.

Problems arising from the use of Spring-service in the filter for permission reasons

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: 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.