I am trying to consume a public web service using spring 2.5.6. I think my code matches the documented instructions, but blows up on initializing the service bean with:
My guess is that either the docs are out of sync with 2.5.6 (again!) or I am using the wrong class for the service and somehow giving Spring the impression that I have a stub from a service that I created (I did not, using a public service). My full code is below.Code:java.lang.ExceptionInInitializerError Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'emailValidateService' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is com.sun.xml.ws.model.RuntimeModelerException: A WebService annotation is not present on class: email.EmailValidateService
Help!!!
applicationContext.xml:
EmailValidateService.java:Code:<?xml version="1.0" encoding="UTF-8"?> <!-- - Spring Application Context --> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd"> <bean id="emailValidateService" class="org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean"> <property name="serviceInterface" value="email.EmailValidateService" /> <property name="wsdlDocumentUrl" value="http://www.webservicex.com/ValidateEmail.asmx?WSDL" /> <property name="namespaceUri" value="http://www.webservicex.net" /> <property name="serviceName" value="ValidateEmail" /> <property name="portName" value="ValidateEmailSoap" /> </bean> <bean id="emailClient" class="email.EmailValidateClientImpl"> <property name="emailValidateService" ref="emailValidateService" /> </bean> </beans>
Test.java:Code:package email; public interface EmailValidateService { public boolean isValidEmail(String emailAddress); }
Code:package email; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class Test { private static ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); private static EmailValidateService service = (EmailValidateService) context.getBean("emailValidateService"); public static void main(String[] args) { try{ System.out.println(service.isValidEmail("support@mks.com")); }catch(Exception e) { e.printStackTrace(); } } }


Reply With Quote