Base API for building infrastructure using spring

Source: Internet
Author: User

First, get the object class name

Class<?> Handlerclass = classutils. Getuserclass (handler);

Second, query whether a method has an annotation

requestmapping mapping = annotationutils. findannotation requestmapping. class );

Iii. obtaining a class that implements an interface

Beanfactoryutils. beansoftypeincludingancestors (Context, handlermapping. class, true, false);

Iv. getting the class object corresponding to a string

Class<?> clazz = classutils. forname (ClassName, this. getclass (). getClassLoader ());  

v. creating managed beans using the Spring context

protected Object Createdefaultstrategy (applicationcontext context, class<?> clazz) {
return context.getautowirecapablebeanfactory (). Createbean (Clazz);
}

Get the Class property of an incoming object and find its registered object name in the Spring container accordingly beanname

Getapplicationcontext (). Getbeannamesfortype (Object. Class)

Querying all beanname registered in the Spring container According to the parent of the incoming object class

Beanfactoryutils. beannamesfortypeincludingancestors (Getapplicationcontext (), Object. class)

In the Spring container, find the corresponding annotation on this object according to Beanname , note that not all annotations

ApplicationContext context = Getapplicationcontext ();
requestmapping mapping = Context.findannotationonbean (Beanname, requestmapping. Class);

Spring uses beanname to find out the class type of this object

class<?> Handlertype = Context.gettype (beanname);

Method Methodtoinvoke = Bridgemethodresolver. Findbridgedmethod (Initbindermethod);

Reflectionutils. makeaccessible (Methodtoinvoke);

X. Getting an object with an annotation

String[] Beannames = (this. Detecthandlersinancestorcontexts ?
Beanfactoryutils. beannamesfortypeincludingancestors (Getapplicationcontext (), Object. class) :
Getapplicationcontext (). Getbeannamesfortype (Object. Class));//Get all beanname

for (String beanname:beannames) {

class<?> Handlertype = Context.gettype (beanname);

ApplicationContext context = Getapplicationcontext ();

if (Annotationutils. findannotation (Handlertype, Controller.) class) ! = null) {

}

}

Xi. Spring Collections static method

Collectionutils.mergearrayintocollection

Base API for building infrastructure using spring

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.