การสนับสนุนเนมสเปซ
ในการใช้การสนับสนุนเนมสเปซจะต้องได้รับการสืบทอดจาก NamespaceHandlersupport
แพ็คเกจ com.codestd.spring.cxf.config.schema; นำเข้า org.springframework.beans.factory.xml.namespacehandlersupport; นำเข้า com.codestd.spring.cxf.config.endpointbeanprocessor; 1.0.0*/คลาสสาธารณะ webserviceannotationnamespaceHandler ขยาย NamespaceHandlersupport {@Overridepublic เป็นโมฆะ init () {// วิธีการที่สร้างอัตโนมัติโดยอัตโนมัติ stubthis.registerbeandefinitionparser ("annotation-endpoint"ใช้เมธอด RegisterBeanDefinitionParser เพื่ออธิบายการสนับสนุนการกำหนดค่าที่เพิ่มเข้ามาในฤดูใบไม้ผลิ คำอธิบายประกอบจุดสิ้นสุดเป็นองค์ประกอบที่รองรับโดยการกำหนดค่า AnnotationBeanDefinitionParser เป็นคลาสที่จัดการการกำหนดค่า EndpointBeanProcessor เป็นคลาสที่ประมวลผล @endpoint ถั่วและจะอธิบายรายละเอียดในภายหลัง
การกำหนดค่าการประมวลผล
จำเป็นต้องใช้ beandefinitionparser
แพ็คเกจ com.codestd.spring.cxf.config.schema; นำเข้า org.springframework.beans.factory.config.beandefinition; นำเข้า org.springframework.beans.factory.support.beandefinition; org.springframework.beans.factory.xml.parsercontext; นำเข้า org.springframework.util.stringutils; นำเข้า org.w3c.dom.element;/*** @author Jaune (Wang Chengwei)*@Since 1.0.0 ชั้น <?> Beanclass; คำอธิบายประกอบสาธารณะ BEANDEFINITIONPARSER (คลาส <?> BeanClass) {this.beanclass = beanclass;}@overridepublic beandefinition parse (องค์ประกอบองค์ประกอบ, parsercontext parsercontext) {rootbeanDefinition RootBeanDefinition (); beanDefinition.setBeanClass (beanClass); beanDefinition.setLazyInit (เท็จ); string id = element.getAttribute ("id"); if (id == null || id.length () == 0) beanclass.getName ();} ถ้า (parsercontext.getRegistry (). containsBeanDefinition (ID)) {โยนใหม่ผิดกฎหมาย EllegalStateException ("ซ้ำ Spring Bean ID" + ID);} parserContext.getRegistry () element.getAttribute ("แพ็คเกจ"); ถ้า (! stringutils.isempty (คำอธิบายประกอบแพคเกจ)) beandefinition.getPropertyValues (). เพิ่ม ("คำอธิบายประกอบ", คำอธิบายประกอบ);สำหรับการประยุกต์ใช้ beandefinitionparser โปรดดูเอกสารประกอบฤดูใบไม้ผลิอย่างเป็นทางการ
คลาสเครื่องมือลงทะเบียนถั่ว
แพ็คเกจ com.codestd.spring.cxf.config; นำเข้า org.springframework.beans.beansexception; นำเข้า org.springframework.beans.factory.config.beandefinition; นำเข้า org.springframework.beans.beans. org.springframework.beans.factory.support.beandefinitionRegistry; นำเข้า org.springframework.context.applicationContext; นำเข้า org.springframework.context.applicationContextAware; ต้องฉีด Spring ApplicationContext.* @author Jaune (Wang Chengwei)* @Since 1.0.0*/คลาสสาธารณะ beanregistry ใช้ ApplicationContextaware {Private ApplicationContext ApplicationContext; Private ConfiguRablePplicationContext ConfigurePplicationContext ApplicationContext; if (applicationcontext อินสแตนซ์ของ configurableapplicationContext) {this.configurableapplicationContext = (configurableapplicationContext) this.applicationContext;}} public beanregistry () {} public beanregistry (ApplicationContext ApplicationContext) clazz) {if (configurableapplicationContext == null) return null; beandefinitionRegistry beanDefinitonRegistry = (beanDefinitionRegistry) configurableapplicationContext.getBeanfactory (); beandefinitionbuilder.getrawbeandefinition (); beandefinitonregistry.registerbeandefinition (clazz.getName (), beandefinition); กลับ beandefinition; beandefinitionbuilder.genericebeandefinition (clazz); return beandefinitionbuilder;}}}การประมวลผล @endpoint
แพ็คเกจ com.codestd.spring.cxf.config; นำเข้า org.springframework.beans.beansexception; นำเข้า org.springframework.beans.factory.disposablebean; นำเข้า org.springframework.beans.factory.config.beanfig. org.springframework.beans.factory.config.configurablelistablebeanfactory; นำเข้า org.springframework.beans.factory.support.beandefinitionregistry; นำเข้า org.springframework.context.aphingcontext; org.springframework.context.annotation.classPathBeanDefinitionScanner; นำเข้า org.springframework.core.type.filter.annotationTypefilter; นำเข้า org.springframework.util.stringutils; Jaune (Wangchengwei)* @since 1.0.0*/คลาสสาธารณะ endpointbeanprocessor ใช้ beanfactorypostprocessor, disposablebean, beanpostprocessor, ApplicationContextaware Beanregistry; โมฆะสาธารณะ setannotationPackage (สตริงคำอธิบายประกอบแพคเกจ) {this.annotationPackage = คำอธิบายประกอบแพ็คเกจ; ถ้า (! stringutils.isempty SetApplicationContext (ApplicationContext ApplicationContext) พ่น beansexception {this.applicationContext = ApplicationContext; this.BeanRegistry = beanRegistry ใหม่ (this.ApplicationContext);}@overridePublic Object Object bean.getClass (). getannotation (endpoint.class); ถ้า (ปลายทาง! = null) {system.out.println (bean.getClass ());} กลับ bean;}@overridepublic วัตถุที่ถูกทำลาย {}/*** แพ็คเกจตรงข้าม* @param Bean* @return*/private boolean isMatchPackage (Object Bean) {ถ้า (AnnotationPackages == NULL || AnnotationPackages.length == 0) {return true; (beanclassname.startswith (pkg)) {return true;}} return false;}/*** scan {@link com.codestd.spring.cxf.annotation.endpoint} annotation*/@overridepublic (AnnotationPackage == NULL || AnnotationPackage.length () == 0) {return;} ถ้า (อินสแตนซ์ beanfactory ของ beandefinitionRegistry) {beandefinitionRegistry beandefinitionRegistry = (beandefinitionregistry) classPathBeanDefinitionScanner (BeanDefinitionRegistry, TRUE); AnnotationTypefilter ตัวกรอง = คำอธิบายประกอบใหม่ TEFEFILTER (Endpoint.class); Scanner.addincludefilter (ตัวกรอง); Scanner.scan (AnnotationPackages); การสแกนคำอธิบายประกอบได้ดำเนินการที่นี่ จากนั้นคุณต้องเขียนรหัสการประมวลผลทางธุรกิจในวิธีการ postprocessafterinitialization Afterinitialization หมายความว่าถั่วได้ถูกสร้างและฉีดด้วยคุณลักษณะ
Postprocessbeforeinitialization ส่วนใหญ่จะใช้ในการฉีดคุณสมบัติเมื่อมีการสร้างอินสแตนซ์ถั่ว
ให้ฤดูใบไม้ผลิรับรู้ส่วนขยาย
ก่อนอื่นสร้าง Spring.handlers ภายใต้ Meta-Inf ใน ClassPath เนื้อหามีดังนี้
http/: //www.codestd.com/schema/std/ws=com.codestd.spring.cxf.config.schema.webserviceannotationnamespaceHandler
ในไฟล์นี้ระบุว่าเนมสเปซใดที่ต้องการคลาสที่จะจัดการ
จากนั้นสร้าง Spring.schemas
http/: //www.codestd.com/schema/std/ws/stdws-1.0.xsd=meta-inf/schema/stdws-1.0.xsd=meta-inf/schema/stdws-1.0.xsd
ระบุตำแหน่งของไฟล์ SECHMA สปริงจะใช้ไฟล์ XSD ที่กำหนดไว้ที่นี่เพื่อตรวจสอบว่าการกำหนดค่าถูกต้อง
ทดสอบ
สร้างอินเทอร์เฟซ
แพ็คเกจ com.codestd.spring.cxf.ws; นำเข้า javax.jws.webservice;/*** @author jaune (wang chengwei)*@since 1.0.0*/@webservicepublic อินเทอร์เฟซ HelloService {Public String Syhi (ชื่อสตริง);คลาสการดำเนินการ
แพ็คเกจ com.codestd.spring.cxf.ws; นำเข้า javax.jws.webservice; นำเข้า com.codestd.spring.cxf.annotation.endpoint;/*** @author Jaune (Wang Chengwei) "HelloServiceendpoint")@webservice (endpointInterface = "com.codestd.spring.cxf.ws.helloservice") ชั้นเรียนสาธารณะ
กรณีทดสอบ
@runwith (springjunit4classrunner.class) @contextconfiguration (locations = {"classpath: applicationcontext.xml"}) การเริ่มต้นคลาสสาธารณะ {@testpublic test test () {}}}} มีส่วนหนึ่งของรหัสในคลาสการประมวลผลที่พิมพ์คลาสทั้งหมดด้วยคำอธิบายประกอบ @endpoint ดังนั้นหากชื่อคลาสถูกพิมพ์ออกมานั่นหมายความว่าการกำหนดค่าเป็นเรื่องปกติ
เรียกใช้กรณีทดสอบ
คอนโซลสามารถมองเห็นได้
คลาส com.codestd.spring.cxf.ws.helloserviceimpl
ผ่านการแนะนำเนื้อหาข้างต้นส่วนขยายนี้จะรับรู้โดยทั่วไป