Extensible spring custom configuration schema (2)

Namespace support

To implement namespace support, you need to inherit from namespacehandlersupport.

Add configuration support to spring through the registerbeandefinitionparser method. Annotation endpoint is an element supported by configuration. Annotationbeandefinitionparser is a class that handles configuration. Endpointbeanprocessor is a class of beans handling @ endpoint annotations, which will be described in detail later.

Processing configuration

Beandefinitionparser needs to be implemented

For the application of beandefinitionparser, see the official spring documentation.

Bean registration tool class

Process @ endpoint

The annotation scanning has been implemented here. Then you need to write the business processing code in the postprocessafterinitialization method. Afterinitialization indicates that the bean has been created and injected with attributes.

Postprocessbeforeinitialization is mainly used to inject attributes during bean instantiation.

Let spring recognize extensions

First, create spring.inf under meta-inf of classpath Handlers, as follows

http\://www.codestd. com/schema/std/ws=com. codestd. spring. cxf. config. schema. WebServiceAnnotationNamespaceHandler

This file indicates which namespace needs which class to handle. Then create spring schemas

http\://www.codestd. com/schema/std/ws/stdws-1.0. xsd=Meta-INF/schema/stdws-1.0. xsd

Indicates the location of the sechma file. Spring will use the XSD file developed here to verify whether the configuration is correct.

test

Create interface

Implementation class

test case

There is a piece of code in the processing class that prints out all classes with @ endpoint annotation, so if the class name is printed out, it means that the configuration is normal.

Run test cases

The console can see

class com. codestd. spring. cxf. ws. HelloServiceImpl

Through the introduction of the above contents, this extension is basically realized.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>