네임 스페이스 지원
네임 스페이스 지원을 구현하려면 Namespacehandlersupport에서 상속해야합니다.
package com.codestd.spring.cxf.config.schema; import org.springframework.beans.factory.xml.namespacehandlersupport; import com.codestd.spring.cxf.config.endpointbeanprocessor;/*** hange namespace*/ssince 1.. Class WebserviceanNotationNamespaceHandler는 NesmepaceHandlersUpport를 확장합니다 {@OverRidePublic void init () {// todo 자동 생성 메소드 stubthis.registerBeanDefinitionParser ( "Annotation-Endpoint", New AnnotationBeanDefinitionParser (endpointBeanProcessor.class));Spring에 추가 된 구성 지원을 설명하려면 RegisterBeanDefinitionParser 메소드를 사용하십시오. 주석-엔드 포인트는 구성에 의해 지원되는 요소입니다. AnnotationBeanDefinitionParser는 구성을 처리하는 클래스입니다. EndpointBeanProcessor는 Bean 주석이 @endpoint를 처리하고 나중에 자세히 설명하는 클래스입니다.
처리 구성
BeanDefinitionParser를 구현해야합니다
packet com.codestd.spring.cxf.config.schema; import org.springframework.beans.config.config.beandefinition; import org.springframework.beans.soofory.support.rootbeandefinition; import org.springframework.bean.xml.beandeparser; org.springframework.bean.beans.factory.xml.parsercontext; import org.springframework.util.stringutils; import org.w3c.dom.element;/*** @auther jaune (wang chengwei)*@since 1.0.0*/public classionbeandefinferser antlementperser instrements instrements instrements intrementeper class <?> beanclass; public annotationBeanDefinitionParser (class <?> beanclass) {this.beanclass = beanclass;}@atederidepublic beandefinition parse (요소 요소, parsercontext parsercontext) {rootbeandefinition beandefinition = new rootBeenDefinition (); beanDefinition.setBeanClass (beanclass); beanDefinition.setLazyInit (false); String id = element = getAttribute ( "id"); if (id == null || id.length () == 0) {string name = element.getAttribute ( "name"); if (if (! if)); beanclass.getName ();} if (parserconText.getRegistry (). containEdefinition (id)) {throw new new 불법 스프링 Bean ID " + id);} parserconText.getRegistry (). RegisterBeanDefinition (ID, BeanDefinition); 요소 .getAttribute ( "package"); if (! stringUtils.isempty (annotationPackage)) beanDefinition.getPropertyValues (). Add ( "AnnotationPackage", AnnotationPackage); 반환 BeanDefinition;}}.BeanDefinitionParser를 적용하려면 공식 스프링 문서를 참조하십시오.
콩 등록 도구 클래스
package com.codestd.spring.cxf.config; import org.springframework.beans.beansexception; import org.sprameframework.beans.beans.config.beandefinition; import org.spramframework.bean.bean.support.beandefinitionbuilder; import org.springframework.bean.beans.support.beandefinitionregistry; import org.springframework.context.applicationcontext; import org.springframework.context.applicationcontextaware; import org.springframework.context.context.configurableApplicationtextextextextete extore extorte 환재 Spring ApplicationContext를 주입해야합니다.* @author jaune (wang chengwei)* @since 1.0.0*/public class beanregistry emplicationscontextaware {private ApplicationContext ApplicationContext; private configurablepplicationcontext configupublic void setapplicationcontext (ApplicationContextextection). {this.applicationContext = ApplicationContext; if (applicationContext instanceOf configUrablePlicationContext) {this.ConfigUrablePlicationContext = (configurableApplicationContext) this.ApplicationContext;}} public beanregistry ()} public beanregistry (ApplicationContext) (ApplicationContext ApplicationContext) {this.setApplicationContext (ApplicationContext);} public beanDefinition Register (class <?> clazz) {if (configurableApplicationContext == null) return null; beanDefinitonRegrestrity = (beanDefinitionRegistry = (beanDefinitionRegistry)) BeanDefinitionBuilder = this.createBuilder (Clazz); BeanDefinition BeanDefinition = BeanDefinitionBuilder.getRawBeanDefinition (); BeanDefinitOnregistry.registerBeanDefinition (Clazz.getName (), BeanDefinition); Reture BeandeFinition; CreateBuilder (class <?> Clazz) {BeanDefinitionBuilder BeanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition (Clazz); return BeanDefinitionBuilder;}}처리 @endpoint
package com.codestd.spring.cxf.config; import org.springframework.beans.beansexception; import org.springframework.beans.beans.disposablebean; import org.springframework.beans.beans.beans.beans.beanfig.beanfactorypostprocessor; import org.springframework.beans.beans.config.configurablelistablebeanfactory; import org.springframework.bean.bean.bean.support.support.beandefinitionregistry; import org.springframework.context.applicationcontext; import org.springframework.context.applicationcontextaware; org.springframework.context.annotation.classpathbeandefinitionscanner; import org.springframework.core.type.filter.annotationtypefilter; import org.springframework.util.stringutils; import motingutils; codestd.spring.cx.annot Jaune (wangchengwei)* @since 1.0.0*/public class endpointbeanprocessor는 beanfactoryposprocessor, proposablebean, beanpostprocessor, applicationcontextaware {private final string comma_split_pattern = ", private applicationcontext; private boorpackages; BeanRegistry; public void setAnnotationPackage (string annotationPackage) {this.annotationPackage = AnnotationPackage; if (! stringUtils.isempty (this.annotationPackage)) this.annotationPackages = this.annotationPackage.split (this.comma_split_pattern); setApplicationContext (ApplicationContext ApplicationContext)는 beansexception {this.applicationContext = ApplicationContext; this.beanRegistry = new beanRegistry (this.applicationContext);}@atriadepublic 객체 PostProcessAfterinitialization (객체 Bean, String Beanname)은 beansexception {if (! this.iscatchpackage (bean)) 반환 Bean; endpoint endpoint = bean.getclass (). null) {system.out.println (bean.getClass ());} return bean;} @retradePublic Object PostProcessBeforeInitialization (Object Bean, String Beanname)은 beansexception {return bean;} @reveridepublic void destrofe () {}/*** @parpact pank*/private ismatchpate를 수행합니다. bean) {if (annotationPackages == null || annotationPackages.length == 0) {return true;} string beanclassname = bean.getClass (). getName (); for (string pkg : annotationPackages) {if (beanclassname.startSwith (pkg)) {retry;}}}}}}}} com.codestd.spring.cxf.annotation.endpoint} annotation*/@atredgepublic void postprocessbeanfactory (configurablelistablebeanfactory beanfactory) beansexception {if (annotationpackage == null || AnnotationPackage.length () == 0) {reture} if (bean em) if (eantationpackage == null || AnnotationPackage.length ()} if (anoTationPackage == null || AnnotationPackage.length ()} if. {BeanDefinitionRegistry BeanDefinitionRegistry = (BeanDefinitionRegistry) BeanFactory; ClassPathBeanDefinitionScanner Scanner = New ClassPathBeanDefinitionScanner (BeanDefinitionRegistry, True); AnnotationTimePefilter = New AnnotationTyPefilter (endpoint.class); Scanner.AddIncludeFilter (필터); Scanner.Scan (AnnotationPackages);}}} 주석 스캔이 여기에서 구현되었습니다. 그런 다음 후 프로세스 감독관에 비즈니스 처리 코드를 작성해야합니다. 이후에 콩이 생성되고 속성이 주입되었음을 의미합니다.
후 프로세스 비 프레종 니티 틸화는 주로 콩 인스턴스화시 특성을 주입하는 데 사용됩니다.
스프링이 확장을 인식하게하십시오
먼저 ClassPath의 Meta-Inf 아래에서 Spring.handlers를 작성하면 내용은 다음과 같습니다.
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 파일의 위치를 지정하면 Spring은 여기에 공식화 된 XSD 파일을 사용하여 구성이 올바른지 확인합니다.
시험
인터페이스를 만듭니다
package com.codestd.spring.cxf.ws; import javax.jws.webservice;/*** @author jaune (wang chengwei)*@since 1.0.0*/@webservicepublic 인터페이스 helloService {public string syhi (문자열 이름);}구현 클래스
package com.codestd.spring.cxf.ws; import javax.jws.webservice; import com.codestd.spring.cxf.annotation.endpoint;/*** @author jaune (wang chengwei)*@since 1.0.0*/ @endpoint (helloService ", id = "HelloServiceEndpoint")@webservice (endpointinterface = "com.codestd.spring.cxf.ws.helloservice") 공개 클래스 HelloServiceImpl은 helloService {@OverridePublic String syhi (String name) {return "hello"+name;}}테스트 사례
@RunWith (SpringJunit4classRunner.class) @ContextConfiguration (위치 = { "classPath : ApplicationContext.xml"}) 공개 클래스 초기화 테스트 {@testpublic void test () {}} 처리 클래스에는 @endpoint 주석으로 모든 클래스를 인쇄하는 코드가 있으므로 클래스 이름이 인쇄되면 구성이 정상임을 의미합니다.
테스트 케이스를 실행하십시오
콘솔에서 볼 수 있습니다
클래스 com.codestd.spring.cxf.ws.helloserviceimpl
위의 내용의 도입을 통해이 확장은 기본적으로 실현됩니다.