JAX-WS结合 spring

1 pom.xml
<!-- Spring dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.2.1.RELEASE</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.2.1.RELEASE</version>
</dependency>

<!-- JAX-WS -->
<dependency>
<groupId>org.jvnet.jax-ws-commons.spring</groupId>
<artifactId>jaxws-spring</artifactId>
<version>1.9</version>
</dependency>

<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.2.8</version>
</dependency>

2 web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">

<display-name>SOAPWebServiceExample</display-name>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
<servlet-name>customer</servlet-name>
<servlet-class>com.sun.xml.ws.transport.http.servlet.WSSpringServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>customer</servlet-name>
<url-pattern>/customer</url-pattern>
</servlet-mapping>

</web-app>


3 customer.java

package com.jcombat.entity;

public class Customer {
private int id;
private String name;

public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}


4

package com.jcombat.services.customers;

import com.jcombat.entity.Customer;

public interface CustomerService {
public Customer getCustomerById(String customerId);
}


5

package com.jcombat.services.customers;

import com.jcombat.entity.Customer;

public class CustomerServiceImpl implements CustomerService {

public Customer getCustomerById(String customerId) {
Customer customer = new Customer();
customer.setId(123);
customer.setName("Abhimanyu");
return customer;
}
}

6 endpoint:

package com.jcombat.ws;

import javax.jws.WebMethod;
import javax.jws.WebService;

import com.jcombat.entity.Customer;
import com.jcombat.services.customers.CustomerService;

@WebService(serviceName = "customerService")
public class CustomerEndpoint {
private CustomerService service;

@WebMethod(exclude = true)
public void setService(CustomerService service) {
this.service = service;
}

@WebMethod(operationName = "getCustomer")
public Customer getCustomerById(String customerId) {
Customer customer = service.getCustomerById(customerId);
return customer;
}

}


7 配置文件:

<?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:ws="http://jax-ws.dev.java.net/spring/core"
xmlns:wss="http://jax-ws.dev.java.net/spring/servlet"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://jax-ws.dev.java.net/spring/core
http://jax-ws.java.net/spring/core.xsd
http://jax-ws.dev.java.net/spring/servlet
http://jax-ws.java.net/spring/servlet.xsd">

<bean id="customerService" class="com.jcombat.services.customers.CustomerServiceImpl">
</bean>

<bean id="customerEndpoint" class="com.jcombat.ws.CustomerEndpoint">
<property name="service" ref="customerService" />
</bean>

<wss:binding url="/customer">
<wss:service>
<ws:service bean="#customerEndpoint" />
</wss:service>
</wss:binding>

</beans>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值