Reference:
Load Order http://blog.csdn.net/wayfoon322/article/details/2418011
Filter using injected bean http://zy116494718.iteye.com/blog/1918131
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