咱们应用的dubbo服务导出,可能没有直接的触发点去发起调用测试,除非本身手写controller和test类,缺少一个动态工具,相似流行的swagger结合controller的测试页面,而swagger-dubbo就能够知足这个自动化测试场景需求。html
dubbo、swagger、springjava
web.xml配置springmvc的DispatcherServletgit
<?xml version="1.0" encoding="UTF-8"?> <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_3_0.xsd" version="3.0" metadata-complete="true"> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:application/*.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>example</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>example</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app>
example-servlet.xml配置springmvc组件github
<?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:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> <mvc:annotation-driven> <!-- 支持fastjson --> <!-- <mvc:message-converters> <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>application/json;charset=UTF-8</value> </list> </property> </bean> </mvc:message-converters> --> </mvc:annotation-driven> <context:annotation-config /> <context:component-scan base-package="com.deepoove.swagger.dubbo.example" /> <context:property-placeholder /> <!-- <context:property-placeholder location="classpath*:swagger-dubbo.properties" /> --> <bean class="com.deepoove.swagger.dubbo.spring.SwaggerDubboConfig" /> <bean class="com.deepoove.swagger.dubbo.example.AnnotationScanConfig" /> <mvc:resources location="/dist/" mapping="/dist/**" /> <mvc:resources location="/distv2/" mapping="/distv2/**" /> <!-- 跨域支持 --> <mvc:cors> <mvc:mapping path="/swagger-dubbo/**" allowed-origins="*" /> <mvc:mapping path="/h/**" allowed-origins="*" /> </mvc:cors> </beans>
工程jar依赖web
<dependency> <groupId>com.deepoove</groupId> <artifactId>swagger-dubbo</artifactId> <version>2.0.3</version> </dependency>
启动服务,访问连接http://127.0.0.1:8080/distv2/index.html,出现swagger的页面,而且输入配置json地址http://127.0.0.1:8080/swagger-dubbo/api-docs,查看显示的接口应该是你服务导出的全部dubbo接口spring
默认dubbo接口或实现类不加任何swagger的注解(好比Api,ApiParam等),则只取到类的基本信息,包括类名、方法、参数名称,因此信息须要本身添加swagger的注解到接口方法上面json
选择一个接口测试,基本参数直接输入,复杂对象输入json串便可,若有访问不通,基本是跨域问题,配置host便可api