Restful和webservice同时存在时的问题

来自ling
跳转至: 导航搜索
package com.deloitte.tms.api.context;

import javax.xml.ws.Endpoint;

import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

import com.deloitte.tms.api.service.iit.webservice.TenantService;

@Configuration
public class WebServiceConfig {

	@Autowired
	private TenantService tenantService;

	@Bean
	public ServletRegistrationBean dispatcherServlet() {
		return new ServletRegistrationBean(new CXFServlet(), "/service/*");// 发布服务名称
	}

	@Bean(name = Bus.DEFAULT_BUS_ID)
	public SpringBus springBus() {
		return new SpringBus();
	}

	@Bean
	public Endpoint endpoint() {
		EndpointImpl endpoint = new EndpointImpl(springBus(), tenantService);// 绑定要发布的服务
		endpoint.publish("/tenantService"); // 显示要发布的名称
		return endpoint;
	}

	/**
	 * 添加普通的controller处理
	 * 
	 * @return
	 */
	@Bean
	public ServletRegistrationBean dispatcherRestServlet() {
		AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
		context.scan("com.deloitte.tms.api.controller");
		DispatcherServlet disp = new DispatcherServlet(context);
		ServletRegistrationBean registrationBean = new ServletRegistrationBean(disp);
		registrationBean.setLoadOnStartup(1);
		// 映射路径自定义,必须设置一个不重复的名称
		registrationBean.addUrlMappings("/rest/*");
		registrationBean.setName("rest");
		return registrationBean;
	}

}