- In Eclipse, new a dynamic web project, say EchoService.
- Provide an interface for EchoService, say EchoService.java, in a custom demo package.
package demo; public interface EchoService { public String echo(String word); }
- Provide an implementation for EchoService interface, say EchoServiceImpl.java.
package demo; public class EchoServiceImpl implements EchoService { public String echo(String word) { return word; } }
- Provide an endpoint to exporting EchoService web service. Make sure that all Spring framework JAR files and commons-logging JAR file are in the build path.
package demo; import javax.jws.WebMethod; import javax.jws.WebParam; import javax.jws.WebService; import org.springframework.beans.factory.annotation.Autowired; @WebService ( targetNamespace = "http://demo/", serviceName="EchoService" ) public class EchoServiceEndpoint { @Autowired private EchoService biz; @WebMethod public String echo( @WebParam(name = "word") String word ) { return biz.echo(word); } }
- Provide applicationContext.xml.
<?xml version="1.0" encoding="UTF-8"?> <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" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"> <context:annotation-config /> <bean id="echoService" class="demo.EchoServiceImpl" /> <bean class="org.springframework.remoting.jaxws.SimpleJaxWsServiceExporter"> <property name="baseAddress" value="http://localhost:8888/" /> </bean> <bean id="echoServiceEndpoint" class="demo.EchoServiceEndpoint"> </bean> </beans>
- Provide a standalone web service publisher, say Main.java.
package demo; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class Main { private static final ApplicationContext ctx = new ClassPathXmlApplicationContext( "demo/applicationContext.xml"); public static void main(String[] args) { System.out.println("Start Standalone JAX-WS Server..."); } }
- Run as Java application (demo.Main). Please check http://localhost:8888/EchoService?wsdl.
Reference:
沒有留言:
張貼留言