dubbox/dubbo+spring+mybatis+gradle构建REST服务

<p><code></p> <h2 id="articleHeader0">杂七杂八的杂</h2> <p>个人博客: <a href="http://joyven.gitee.io/devo" rel="nofollow noreferrer" target="_blank">呆萌的程序猿</a><br />原文:<a href="http://joyven.gitee.io/devo/2016/05/21/dubbox:dubbo+spring+mybatis+gradle%E6%9E%84%E5%BB%BAREST%E6%9C%8D%E5%8A%A1/" rel="nofollow noreferrer" target="_blank">dubbox/dubbo+spring+mybatis+gradle构建REST服务</a><br />声明:<br />由于sf的编辑自动校验,导致某些英文单词出错,例如:<code>gradle</code>被编辑器自动替换为<code>grade</code>,<code>jdk</code>替换为<code>idk</code>等,查看的时候,请自行翻译。</p> <p>------------------------------多图预警------------------------------</p> <p>什么是dubbox?看看别人怎么说的:</p> <blockquote> <p>Dubbox是Dubbo的一个扩展,假如你知道java, javax 和 dubbo,那你就会明白dubbox是什么了。</p> <p>Dubbox增加的功能如RESTful remoting, Kyro/FST 系列化等。它已经应用在当当网内部的多个项目中。</p> </blockquote> <h2 id="articleHeader1">dubbox的功能</h2> <ul> <li>支持REST风格远程调用(HTTP + JSON/XML):基于非常成熟的JBoss RestEasy框架,在dubbo中实现了REST风格(HTTP + JSON/XML)的远程调用,以显著简化企业内部的跨语言交互,同时显著简化企业对外的Open API、无线API甚至AJAX服务端等等的开发。事实上,这个REST调用也使得Dubbo可以对当今特别流行的“微服务”架构提供基础性支持。 另外,REST调用也达到了比较高的性能,在基准测试下,HTTP + JSON与Dubbo 2.x默认的RPC协议(即TCP + Hessian2二进制序列化)之间只有1.5倍左右的差距,详见文档中的基准测试报告。</li> <li>支持基于Kryo和FST的Java高效序列化实现:基于当今比较知名的Kryo和FST高性能序列化库,为Dubbo 默认的RPC协议添加新的序列化实现,并优化调整了其序列化体系,比较显著的提高了Dubbo RPC的性能,详见文档中的基准测试报告。</li> <li>支持基于嵌入式Tomcat的HTTP remoting体系:基于嵌入式tomcat实现dubbo 的HTTP remoting体系(即dubbo-remoting-http),用以逐步取代Dubbo中旧版本的嵌入式Jetty,可以显著的提高REST等的远程调用性能,并将Servlet API的支持从2.5升级到3.1。(注:除了REST,dubbo中的WebServices、Hessian、HTTP Invoker等协议都基于这个HTTP remoting体系)。</li> <li>升级Spring:将dubbo中Spring由2.x升级到目前最常用的3.x版本,减少版本冲突带来的麻烦</li> <li>升级ZooKeeper客户端:将dubbo中的zookeeper客户端升级到最新的版本,以修正老版本中包含的bug。</li> <li>调整Demo应用:暂时将dubbo的demo应用调整并改写以主要演示REST功能和新的Java高效序列化等等。</li> <li>修正了在JDK1.7上dubbo的部分bug:修正了比如dubbo协议中json序列化的问题。但是还没有修正所有发现的bug。</li> </ul> <p>注:dubbox和dubbo 2.x是兼容的,没有改变dubbo的任何已有的功能和配置方式(除了升级了spring之类的版本)</p> <hr> <p>注:以上文字均为<a href="http://www.open-open.com/lib/view/open1416206204977.html" rel="nofollow noreferrer" target="_blank">《Dubbo扩展:Dubbox》</a>一文。</p> <h2 id="articleHeader2">环境安装</h2> <h3 id="articleHeader3">jdk安装</h3> <p>能看此文的人,我假设你会安装java开发环境,此处省略999+的废话,否则你看到此处心中一定会奔腾着十万匹草泥马。</p> <h3 id="articleHeader4">gradle安装</h3> <p>如题,Mac开发环境,windows请自行实践,如果出了什么问题,别骂我就行。</p> <p>废话少说,言归正传。</p> <p>相信你看到这里会对gradle多多少少有些了解,如果不了解,也没关系,gradle就是maven的升级版,也适用于java项目的包管理器,它抛弃了如maven基于xml的繁琐配置。</p> <blockquote> <p><a href="http://blog.csdn.net/maosidiaoxian/article/details/40109337" rel="nofollow noreferrer" target="_blank">Gradle是一个基于JVM的构建工具</a>,它提供了:</p> <ul> <li>像Ant一样,通用灵活的构建工具</li> <li>可以切换的,基于约定的构建框架</li> <li>强大的多工程构建支持</li> <li>基于Apache Ivy的强大的依赖管理</li> <li>支持maven, Ivy仓库</li> <li>支持传递性依赖管理,而不需要远程仓库或者是pom.xml和ivy.xml配置文件。</li> <li>对Ant的任务做了很好的集成</li> <li>基于Groovy,build脚本使用Groovy编写</li> <li>有广泛的领域模型支持构建</li> </ul> </blockquote> <p><strong>安装jdk</strong>。安装gradle之前一定先安装jdk,并配置JAVA_HOME环境变量。因为gradle是用Groovy编写的,而Groovy基于JAVA。</p> <p>用vim打开根目录下的 ~/.bashrc或者~/.bash_profile配置用户级别的环境变量,或者打开/etc/profile文件配置系统级别的环境变量,将下面的内容复制到上述文件之一保存(vim保存,编辑后先按ESC进入命令模式,输入:wq保存并退出,然后加载配置后的文件,用命令<code>source ~/.bashrc</code>或者<code>source ~/.bash_profile</code>或者<code>source /etc/profile</code>)即可。</p> <div class="widget-codetool" style="display:none;"> <div class="widget-codetool--inner"> <span class="selectCode code-tool" data-toggle="tooltip" data-placement="top" title="" data-original-title="全选"></span> <span type="button" class="copyCode code-tool" data-toggle="tooltip" data-placement="top" data-clipboard-text=" JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home" title="" data-original-title="复制"></span> </div> </p></div> <pre class="shell hljs"><code class="shell" style="word-break: break-word; white-space: initial;"> JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home</code></pre> <p><strong>下载</strong>。在<a href="https://gradle.org/gradle-download/" rel="nofollow noreferrer" target="_blank">这里</a>下载gradle。</p> <p><span class="img-wrap"><img data-src="/img/bVvQ7H?w=1302&amp;h=1390" src="https://static.segmentfault.com/v-5cc2cd8e/global/img/squares.svg" alt="图片描述" title="图片描述" style="cursor: pointer;"></span><br /><strong>解压</strong>。<br />下载好的文件是zip格式,mac下载后自动解压,如果没有自动解压,在findler中打开下载目录,双击即可解压,如果还不行,执行命令解压,mac自带了unzip命令工具,如果没有unzip,使用brew安装吧。</p> <p>安装unzip命令:</p> <div class="widget-codetool" style="display:none;"> <div class="widget-codetool--inner"> <span class="selectCode code-tool" data-toggle="tooltip" data-placement="top" title="" data-original-title="全选"></span> <span type="button" class="copyCode code-tool" data-toggle="tooltip" data-placement="top" data-clipboard-text="brew install unzip" title="" data-original-title="复制"></span> </div> </p></div> <pre class="hljs sql"><code style="word-break: break-word; white-space: initial;">brew <span class="hljs-keyword">install</span> unzip</code></pre> <p>解压zip文件命令:</p> <div class="widget-codetool" style="display:none;"> <div class="widget-codetool--inner"> <span class="selectCode code-tool" data-toggle="tooltip" data-placement="top" title="" data-original-title="全选"></span> <span type="button" class="copyCode code-tool" data-toggle="tooltip" data-placement="top" data-clipboard-text="cd /Users/xxx/Downloads &amp;&amp; unzip gradle-2.13-all.zip" title="" data-original-title="复制"></span> </div> </p></div> <pre class="hljs groovy"><code style="word-break: break-word; white-space: initial;">cd <span class="hljs-regexp">/Users/</span>xxx/Downloads &amp;&amp; unzip gradle<span class="hljs-number">-2.13</span>-all.zip</code></pre> <p>上面命令解释:cd首先进入到你的工作空间,xxx替换为个人用户名;然后执行unzip命令解压gradle。</p> <blockquote> <p>PS:说一下我的安装习惯吧。</p> <p>一般情况下,用命令安装的软件基本都在/usr/local/Cellar/目录下面,二进制文件可能会软连接到/usr/local/bin/和/usr/local/sbin/目录下面,配置文件在/usr/local/etc/目录下面。</p> <p>但是,有一些软件还是喜欢放在个人工作空间,用起来比较方便。比如tomcat,zookeeper,gradle,jmeter等工具,放在用户目录下面的Documents/software目录下,software原来没有,自建一个software文件夹。</p> <p><span class="img-wrap"><img data-src="/img/bVvQ8o?w=544&amp;h=448" src="https://static.segmentfault.com/v-5cc2cd8e/global/img/squares.svg" alt="图片描述" title="图片描述" style="cursor: pointer;"></span></p> <p>上面是我的工作空间。只希望给自己创建一个干净整齐的工作空间。</p> </blockquote> <h3 id="articleHeader5">gradle配置</h3> <p>在gradle的根目录下面,找到init.d目录,这就是它的配置文件夹,里面有一个磨人的配置文件init.gradle。</p> <div class="widget-codetool" style="display:none;"> <div class="widget-codetool--inner"> <span class="selectCode code-tool" data-toggle="tooltip" data-placement="top" title="" data-original-title="全选"></span> <span type="button" class="copyCode code-tool" data-toggle="tooltip" data-placement="top" data-clipboard-text="allprojects { apply plugin: 'java' apply plugin: 'idea' buildDir = 'target' buildDir = 'target' repositories { // maven repository maven { url 'http://127.0.0.1:8082/nexus/content/groups/public/' } mavenLocal() mavenCentral() } buildscript { repositories { maven { url 'http://127.0.0.1:8082/nexus/content/groups/public/' } mavenLocal() mavenCentral() } dependencies { classpath 'net.nisgits.gradle:gradle-executable-jar-plugin:1.7.0' } } } " title="" data-original-title="复制"></span> </div> </p></div> <pre class="hljs properties"><code><span class="hljs-attr">allprojects</span> <span class="hljs-string">{</span> <span class="hljs-attr">apply</span> <span class="hljs-string">plugin: 'java'</span> <span class="hljs-attr">apply</span> <span class="hljs-string">plugin: 'idea'</span> <span class="hljs-attr">buildDir</span> = <span class="hljs-string">'target'</span> <span class="hljs-attr">buildDir</span> = <span class="hljs-string">'target'</span> <span class="hljs-attr">repositories</span> <span class="hljs-string">{</span> <span class="hljs-meta">//</span> <span class="hljs-string">maven repository</span> <span class="hljs-attr">maven</span> <span class="hljs-string">{</span> <span class="hljs-attr">url</span> <span class="hljs-string">'http://127.0.0.1:8082/nexus/content/groups/public/'</span> <span class="hljs-attr">}</span> <span class="hljs-attr">mavenLocal()</span> <span class="hljs-attr">mavenCentral()</span> <span class="hljs-attr">}</span> <span class="hljs-attr">buildscript</span> <span class="hljs-string">{</span> <span class="hljs-attr">repositories</span> <span class="hljs-string">{</span> <span class="hljs-attr">maven</span> <span class="hljs-string">{</span> <span class="hljs-attr">url</span> <span class="hljs-string">'http://127.0.0.1:8082/nexus/content/groups/public/'</span> <span class="hljs-attr">}</span> <span class="hljs-attr">mavenLocal()</span> <span class="hljs-attr">mavenCentral()</span> <span class="hljs-attr">}</span> <span class="hljs-attr">dependencies</span> <span class="hljs-string">{</span> <span class="hljs-attr">classpath</span> <span class="hljs-string">'net.nisgits.gradle:gradle-executable-jar-plugin:1.7.0'</span> <span class="hljs-attr">}</span> <span class="hljs-attr">}</span> <span class="hljs-attr">}</span> </code></pre> <p>上面的仓库地址可以改成你自己的maven仓库,也可以指定为第三方的maven仓库。我这里是本地搭建的,请记得<strong><em>修改</em></strong>。</p> <h3 id="articleHeader6">tomcat安装</h3> <p><strong>下载</strong>:tomcat的下载点击<a href="http://tomcat.apache.org" rel="nofollow noreferrer" target="_blank">这里</a><br />首先登录官网,点击导航菜单的download,进入下载页面。左边栏就能看到download的下面的一些版本,建议下载8,不要用9,这里只说mac的,我尝试了几次,9在IDEA编辑中运行代码回报错误权限不足,而我的tomcat的意境是777的权限,网上查了一下,也没有更好的解决方案,都是chmod给*.sh权限。</p> <p><span class="img-wrap"><img data-src="/img/bVvQ81?w=1104&amp;h=1060" src="https://static.segmentfault.com/v-5cc2cd8e/global/img/squares.svg" alt="图片描述" title="图片描述" style="cursor: pointer;"></span><br />以8版本为例,点击进入之后就是这样的:</p> <p><span class="img-wrap"><img data-src="/img/bVvQ9p?w=1436&amp;h=1266" src="https://static.segmentfault.com/v-5cc2cd8e/global/img/squares.svg" alt="图片描述" title="图片描述" style="cursor: pointer;"></span></p> <p>mac和linux用户还是选择tar.gz格式,我们只需要下载Core的包,其他的估计也用不上,完整文档的就别下载了,我相信自己不会去看的,除非你不相信自己或者过分相信自己。<br />解压:使用tar命令就好,假设你已经进入到下载目录:</p> <div class="widget-codetool" style="display:none;"> <div class="widget-codetool--inner"> <span class="selectCode code-tool" data-toggle="tooltip" data-placement="top" title="" data-original-title="全选"></span> <span type="button" class="copyCode code-tool" data-toggle="tooltip" data-placement="top" data-clipboard-text="tar -zxvf apache-tomcat-8.0.35.tar" title="" data-original-title="复制"></span> </div> </p></div> <pre class="hljs css"><code style="word-break: break-word; white-space: initial;"><span class="hljs-selector-tag">tar</span> <span class="hljs-selector-tag">-zxvf</span> <span class="hljs-selector-tag">apache-tomcat-8</span><span class="hljs-selector-class">.0</span><span class="hljs-selector-class">.35</span><span class="hljs-selector-class">.tar</span></code></pre> <p>忽然发现,下载的tomcat8的文件格式不是tar.gz,而是tar;tomcat9的却是tar.gz。不管哪一种,解压命令一样,都可达到你要的效果。</p> <h3 id="articleHeader7">zookeeper安装</h3> <p>zk的下载和安装网上有很多教程,这里不做详细的讲解。默认情况下,运行代码之前假设已经开启了zk,开启命令:</p> <div class="widget-codetool" style="display:none;"> <div class="widget-codetool--inner"> <span class="selectCode code-tool" data-toggle="tooltip" data-placement="top" title="" data-original-title="全选"></span> <span type="button" class="copyCode code-tool" data-toggle="tooltip" data-placement="top" data-clipboard-text="sudo sh zkServer.sh start" title="" data-original-title="复制"></span> </div> </p></div> <pre class="hljs sql"><code style="word-break: break-word; white-space: initial;">sudo sh zkServer.sh <span class="hljs-keyword">start</span></code></pre> <p><strong>再次强调</strong>,运行dubbox/dubbo构建的代码,一定要开启zk,端口默认2181,如果你修改了端口,后面提到的config.properties文件中记得修改。</p> <h2 id="articleHeader8">用IDEA搭建框架</h2> <blockquote> <p>帮助别人,其实是在帮助自己;纪录总会有用处,只是需要到一定的时机。<br />[写作感悟]<br />环境终于配置结束了。</p> </blockquote> <p>首先搭建一个简单的gradle的project。</p> <p>打开IDEA,选择创建一个新工程[Create New Project]<br /><span class="img-wrap"><img data-src="/img/bVvRa2?w=958&amp;h=914" src="https://static.segmentfault.com/v-5cc2cd8e/global/img/squares.svg" alt="图片描述" title="图片描述" style="cursor: pointer;"></span></p> <p>选择gradle,然后选择jdk,右下角next:<br /><span class="img-wrap"><img data-src="/img/bVvRa3?w=1894&amp;h=1444" src="https://static.segmentfault.com/v-5cc2cd8e/global/img/squares.svg" alt="图片描述" title="图片描述" style="cursor: pointer;"></span></p> <p>接下来填写groupie,artifacts,version,这三个值构成了一个坐标系统,这是maven标识一个工程的唯一依据,gradle依然在使用这个坐标。<br /><span class="img-wrap"><img data-src="/img/bVvRbb?w=1902&amp;h=1444" src="https://static.segmentfault.com/v-5cc2cd8e/global/img/squares.svg" alt="图片描述" title="图片描述" style="cursor: pointer;"></span></p> <p>本地配置了gradle,就选择使用本地的吧,勾选一下自动创建空内容根目录,也就是帮你创建了src,resource等资源文件夹:<br /><span class="img-wrap"><img data-src="/img/bVvRbP?w=1908&amp;h=1446" src="https://static.segmentfault.com/v-5cc2cd8e/global/img/squares.svg" alt="图片描述" title="图片描述" style="cursor: pointer;"></span></p> <p>接下来可以改一下project name为test-demo.<br />我们的工程目录如下:<br /><span class="img-wrap"><img data-src="/img/bVvRcp?w=876&amp;h=1350" src="https://static.segmentfault.com/v-5cc2cd8e/global/img/squares.svg" alt="图片描述" title="图片描述" style="cursor: pointer;"></span></p> <p>IDEA很神奇,提供了命令窗口,当然没有mac的好用,对中文的致辞不友好。在改窗口下输入命令(build命令在以后经常用到,用于构建打包):</p> <div class="widget-codetool" style="display:none;"> <div class="widget-codetool--inner"> <span class="selectCode code-tool" data-toggle="tooltip" data-placement="top" title="" data-original-title="全选"></span> <span type="button" class="copyCode code-tool" data-toggle="tooltip" data-placement="top" data-clipboard-text="gradle clean idea build --daemon" title="" data-original-title="复制"></span> </div> </p></div> <pre class="hljs sql"><code style="word-break: break-word; white-space: initial;">gradle clean idea build <span class="hljs-comment">--daemon</span></code></pre> <p>或者</p> <div class="widget-codetool" style="display:none;"> <div class="widget-codetool--inner"> <span class="selectCode code-tool" data-toggle="tooltip" data-placement="top" title="" data-original-title="全选"></span> <span type="button" class="copyCode code-tool" data-toggle="tooltip" data-placement="top" data-clipboard-text=" gradle clean build --daemon gradle clean idea" title="" data-original-title="复制"></span> </div> </p></div> <pre class="hljs properties"><code> <span class="hljs-attr">gradle</span> <span class="hljs-string">clean build --daemon</span> <span class="hljs-attr">gradle</span> <span class="hljs-string">clean idea</span></code></pre> <h2 id="articleHeader9">配置gradle工程依赖</h2> <p>打开工程目录下的build.gradle文件,配置dubbed/dubbo、spring、zk、öson等依赖包下面的配置中spring的版本是3.x,你可选择配置4.x版本。</p> <div class="widget-codetool" style="display:none;"> <div class="widget-codetool--inner"> <span class="selectCode code-tool" data-toggle="tooltip" data-placement="top" title="" data-original-title="全选"></span> <span type="button" class="copyCode code-tool" data-toggle="tooltip" data-placement="top" data-clipboard-text="group 'Joyven' version '1.0-SNAPSHOT' apply plugin: 'java' apply plugin: 'war' sourceCompatibility = 1.8 repositories { mavenLocal() mavenCentral() } dependencies { compile 'com.google.code.gson:gson:2.3.1' // log4j2 compile 'org.apache.logging.log4j:log4j-core:2.4.1' compile 'org.apache.logging.log4j:log4j-api:2.4.1' compile 'org.apache.logging.log4j:log4j-slf4j-impl:2.4.1' // validator compile 'org.hibernate:hibernate-validator:5.2.0.Final' compile 'javax.validation:validation-api:1.1.0.Final' compile 'org.jboss.resteasy:jaxrs-api:3.0.7.Final' //http 异步 compile 'org.apache.httpcomponents:httpasyncclient:4.1.1' // dubbo compile ('com.alibaba:dubbo:2.8.4') { exclude(module: 'log4j') } compile 'com.alibaba:dubbo-rpc-rest:2.8.4' // jackson compile 'com.fasterxml.jackson.core:jackson-core:2.7.0-rc2' compile 'com.fasterxml.jackson.core:jackson-databind:2.7.0-rc2' compile 'org.apache.kafka:kafka-clients:0.9.0.0' compile 'com.alibaba.rocketmq:rocketmq-client:3.2.6' //mongodb compile 'org.springframework.data:spring-data-mongodb:1.8.0.RELEASE' compile 'org.mongodb:mongo-java-driver:3.1.0' compile 'com.alibaba:druid:1.0.15' compile 'org.mybatis:mybatis:3.3.0' compile 'org.mybatis:mybatis-spring:1.2.3' compile 'mysql:mysql-connector-java:5.1.36' compile 'joda-time:joda-time:2.8.1' compile 'org.springframework:spring-jdbc:3.2.9.RELEASE' compile 'org.springframework:spring-test:3.2.9.RELEASE' compile 'org.springframework:spring-webmvc:3.0.9.RELEASE' compile 'org.springframework.hateoas:spring-hateoas:0.19.0.RELEASE' compile 'org.glassfish:javax.el:3.0.1-b08' compile 'commons-beanutils:commons-beanutils:1.8.3' compile 'org.apache.zookeeper:zookeeper:3.5.0-alpha' compile 'com.github.sgroschupf:zkclient:0.1' compile 'log4j:log4j:1.2.17' testCompile 'junit:junit:4.11' } war { archiveName = &quot;test-demo.war&quot; }" title="" data-original-title="复制"></span> </div> </p></div> <pre class="hljs groovy"><code>group <span class="hljs-string">'Joyven'</span> version <span class="hljs-string">'1.0-SNAPSHOT'</span> apply <span class="hljs-string">plugin:</span> <span class="hljs-string">'java'</span> apply <span class="hljs-string">plugin:</span> <span class="hljs-string">'war'</span> sourceCompatibility = <span class="hljs-number">1.8</span> repositories { mavenLocal() mavenCentral() } dependencies { compile <span class="hljs-string">'com.google.code.gson:gson:2.3.1'</span> <span class="hljs-comment">// log4j2</span> compile <span class="hljs-string">'org.apache.logging.log4j:log4j-core:2.4.1'</span> compile <span class="hljs-string">'org.apache.logging.log4j:log4j-api:2.4.1'</span> compile <span class="hljs-string">'org.apache.logging.log4j:log4j-slf4j-impl:2.4.1'</span> <span class="hljs-comment">// validator</span> compile <span class="hljs-string">'org.hibernate:hibernate-validator:5.2.0.Final'</span> compile <span class="hljs-string">'javax.validation:validation-api:1.1.0.Final'</span> compile <span class="hljs-string">'org.jboss.resteasy:jaxrs-api:3.0.7.Final'</span> <span class="hljs-comment">//http 异步</span> compile <span class="hljs-string">'org.apache.httpcomponents:httpasyncclient:4.1.1'</span> <span class="hljs-comment">// dubbo</span> compile (<span class="hljs-string">'com.alibaba:dubbo:2.8.4'</span>) { exclude(<span class="hljs-string">module:</span> <span class="hljs-string">'log4j'</span>) } compile <span class="hljs-string">'com.alibaba:dubbo-rpc-rest:2.8.4'</span> <span class="hljs-comment">// jackson</span> compile <span class="hljs-string">'com.fasterxml.jackson.core:jackson-core:2.7.0-rc2'</span> compile <span class="hljs-string">'com.fasterxml.jackson.core:jackson-databind:2.7.0-rc2'</span> compile <span class="hljs-string">'org.apache.kafka:kafka-clients:0.9.0.0'</span> compile <span class="hljs-string">'com.alibaba.rocketmq:rocketmq-client:3.2.6'</span> <span class="hljs-comment">//mongodb</span> compile <span class="hljs-string">'org.springframework.data:spring-data-mongodb:1.8.0.RELEASE'</span> compile <span class="hljs-string">'org.mongodb:mongo-java-driver:3.1.0'</span> compile <span class="hljs-string">'com.alibaba:druid:1.0.15'</span> compile <span class="hljs-string">'org.mybatis:mybatis:3.3.0'</span> compile <span class="hljs-string">'org.mybatis:mybatis-spring:1.2.3'</span> compile <span class="hljs-string">'mysql:mysql-connector-java:5.1.36'</span> compile <span class="hljs-string">'joda-time:joda-time:2.8.1'</span> compile <span class="hljs-string">'org.springframework:spring-jdbc:3.2.9.RELEASE'</span> compile <span class="hljs-string">'org.springframework:spring-test:3.2.9.RELEASE'</span> compile <span class="hljs-string">'org.springframework:spring-webmvc:3.0.9.RELEASE'</span> compile <span class="hljs-string">'org.springframework.hateoas:spring-hateoas:0.19.0.RELEASE'</span> compile <span class="hljs-string">'org.glassfish:javax.el:3.0.1-b08'</span> compile <span class="hljs-string">'commons-beanutils:commons-beanutils:1.8.3'</span> compile <span class="hljs-string">'org.apache.zookeeper:zookeeper:3.5.0-alpha'</span> compile <span class="hljs-string">'com.github.sgroschupf:zkclient:0.1'</span> compile <span class="hljs-string">'log4j:log4j:1.2.17'</span> testCompile <span class="hljs-string">'junit:junit:4.11'</span> } war { archiveName = <span class="hljs-string">"test-demo.war"</span> }</code></pre> <p>最后一行的意思是,gradle build的时候,打包的war包文件名,不是带有一串很长的groupid,version等信息的包名,而是指定的包,如<code>test-demo.war</code>。</p> <p>配置玩gradle后,执行上面说过的build命令<code>gradle clean build --daemon</code>,构建依赖包,此过程如果用的是第三方的maven仓库,可能事件会很长。</p> <p>----------- 本来以为一篇就写完了,前戏太长,一篇容纳不下,但是,sf表字段肯定足够大,表担心,我们还是继续把这场戏演完------------</p> <h2 id="articleHeader10">项目基本配置</h2> <h3 id="articleHeader11">工程结构</h3> <p>在main文件夹下面新建一个webapp,webapp下心间一个WEB-INF,web.xml就在WEB-INF目录下面。</p> <div class="widget-codetool" style="display:none;"> <div class="widget-codetool--inner"> <span class="selectCode code-tool" data-toggle="tooltip" data-placement="top" title="" data-original-title="全选"></span> <span type="button" class="copyCode code-tool" data-toggle="tooltip" data-placement="top" data-clipboard-text="|____build.gradle |____settings.gradle |____src | |____main | | |____java | | |____resources | | |____webapp | | | |____index.jsp | | | |____WEB-INF | | | | |____web.xml | |____test | | |____java | | |____resources |____target " title="" data-original-title="复制"></span> </div> </p></div> <pre class="hljs ruby"><code><span class="hljs-params">|____build.gradle |</span>____settings.gradle <span class="hljs-params">|____src |</span> <span class="hljs-params">|____main |</span> <span class="hljs-params">| |</span>____java <span class="hljs-params">| |</span> <span class="hljs-params">|____resources |</span> <span class="hljs-params">| |</span>____webapp <span class="hljs-params">| |</span> <span class="hljs-params">| |</span>____index.jsp <span class="hljs-params">| |</span> <span class="hljs-params">| |</span>____WEB-INF <span class="hljs-params">| |</span> <span class="hljs-params">| |</span> <span class="hljs-params">|____web.xml |</span> <span class="hljs-params">|____test |</span> <span class="hljs-params">| |</span>____java <span class="hljs-params">| |</span> <span class="hljs-params">|____resources |</span>____target </code></pre> <p>上面的目录结构就是我的工程结构,其中一部份idea和gradle的文件没有贴出来。</p> <h3 id="articleHeader12">spring配置</h3> <p>在resource目录下创建一个文件夹:META-INF.spring,在改文件夹下面创建一个spring配置文件services-config.xml。</p> <div class="widget-codetool" style="display:none;"> <div class="widget-codetool--inner"> <span class="selectCode code-tool" data-toggle="tooltip" data-placement="top" title="" data-original-title="全选"></span> <span type="button" class="copyCode code-tool" data-toggle="tooltip" data-placement="top" data-clipboard-text="<?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> <!-- - Copyright 1999-2011 Alibaba Group. - - Licensed under the Apache License, Version 2.0 (the &quot;License&quot;); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an &quot;AS IS&quot; BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. --> <beans data-original-title="复制"></span> </div> </p></div> <pre class="hljs xml"><code><span class="hljs-meta">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</span> <span class="hljs-comment">&lt;!-- - Copyright 1999-2011 Alibaba Group. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. --&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">beans</span> <span class="hljs-attr">>"http://www.springframework.org/schema/beans"</span> <span class="hljs-attr">>"http://www.springframework.org/schema/context"</span> <span class="hljs-attr">>"http://www.w3.org/2001/XMLSchema-instance"</span> <span class="hljs-attr">>"http://code.alibabatech.com/schema/dubbo"</span> <span class="hljs-attr">>"http://www.springframework.org/schema/tx"</span> <span class="hljs-attr">>"http://www.springframework.org/schema/task"</span> <span class="hljs-attr">xsi:schemaLocation</span>=<span class="hljs-string">"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.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd "</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">task:annotation-driven</span>/&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">context:annotation-config</span>/&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">context:component-scan</span> <span class="hljs-attr">base-package</span>=<span class="hljs-string">""</span>/&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"systemPropertiesModeName"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"SYSTEM_PROPERTIES_MODE_OVERRIDE"</span>/&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"ignoreResourceNotFound"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"true"</span>/&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"locations"</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">list</span>&gt;</span> <span class="hljs-comment">&lt;!-- 越靠后越有效,取到最后一个有效的未知 --&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>classpath:conf/properties/*.properties<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span> <span class="hljs-tag">&lt;/<span class="hljs-name">list</span>&gt;</span> <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span> <span class="hljs-tag">&lt;/<span class="hljs-name">bean</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">dubbo:application</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"test-demo"</span> <span class="hljs-attr">owner</span>=<span class="hljs-string">"Joyven"</span> <span class="hljs-attr">organization</span>=<span class="hljs-string">"freedom"</span>/&gt;</span> <span class="hljs-comment">&lt;!--激活注解--&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"org.springframework.context.annotation.CommonAnnotationBeanPostProcessor"</span>/&gt;</span> <span class="hljs-comment">&lt;!-- 声明需要暴露的服务接口 --&gt;</span> <span class="hljs-comment">&lt;!-- &lt;dubbo:protocol name="dubbo" port="${dubbo.server.port}" host="${dubbo.server.host}"/&gt;--&gt;</span> <span class="hljs-comment">&lt;!--&lt;dubbo:monitor protocol="registry" /&gt;--&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">dubbo:registry</span> <span class="hljs-attr">protocol</span>=<span class="hljs-string">"zookeeper"</span> <span class="hljs-attr">address</span>=<span class="hljs-string">"${zkHost}"</span>/&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">dubbo:protocol</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"rest"</span> <span class="hljs-attr">port</span>=<span class="hljs-string">"${rest.server.port}"</span> <span class="hljs-attr">threads</span>=<span class="hljs-string">"500"</span> <span class="hljs-attr">contextpath</span>=<span class="hljs-string">"test-demo"</span> <span class="hljs-attr">server</span>=<span class="hljs-string">"servlet"</span> <span class="hljs-attr">accepts</span>=<span class="hljs-string">"500"</span> <span class="hljs-attr">extension</span>=<span class="hljs-string">"com.alibaba.dubbo.rpc.protocol.rest.support.LoggingFilter"</span>/&gt;</span> <span class="hljs-comment">&lt;!-- 声明需要暴露的服务接口 --&gt;</span> <span class="hljs-tag">&lt;/<span class="hljs-name">beans</span>&gt;</span></code></pre> <p>说明:</p> <ul> <li>该文件配置的就是你所期望的dubbox/dubbo和spring的信息。<code>&lt;context:component-scan base-package=""/&gt;</code>这一句配置的内容暂时为空,后面要指定我们要扫描的包。</li> <li> <code>&lt;dubbo:application name="test-demo" owner="Joyven" organization="freedom"/&gt;</code>这一句指出dubbo应用的名字、所属以及组织,name一半填写工程名字,owner一般指定为公司,或者项目组,organization一般为公司,我是自用组织者,哈哈?~~</li> <li>估计眼明的你已经看到了,&lt;dubbo:registry protocol="zookeeper" address="${zkHost}"/&gt;&lt;dubbo:protocol name="rest" port="${rest.server.port}" threads="500" contextpath="test-demo" server="servlet" accepts="500"<br />extension="com.alibaba.dubbo.rpc.protocol.rest.support.LoggingFilter"/&gt;,这里面的配置都是动态获取的,<code>${variable}</code>指代properties文件中配置的属性。</li> <li>port的配置必须与服务器的端口相同,这个是实现rest服务所必须要求的,而在dubbo中是不做要求的,因为dubbo只是一个服务提供方,不提供直接通过http协议访问。</li> <li>contextpath路径必须与工程部署的路径相同,意思呢,就是contextpath的值和war包的名字一样。</li> <li>server 如果不指定,默认启动Jetty服务器,如果是tomcat指定servlet,方便在web.xml中配置rest过滤器。如果配置成tomcat,则会出现一些错误。</li> </ul> <p>配置properties文件,在main/conf/properties/config.properties:</p> <div class="widget-codetool" style="display:none;"> <div class="widget-codetool--inner"> <span class="selectCode code-tool" data-toggle="tooltip" data-placement="top" title="" data-original-title="全选"></span> <span type="button" class="copyCode code-tool" data-toggle="tooltip" data-placement="top" data-clipboard-text="server.port=30010 dubbo.server.port=30011 dubbo.server.host=127.0.0.1 rest.server.port=8080 zkHost=127.0.0.1:2181 " title="" data-original-title="复制"></span> </div> </p></div> <pre class="hljs makefile"><code>server.port=30010 dubbo.server.port=30011 dubbo.server.host=127.0.0.1 rest.server.port=8080 zkHost=127.0.0.1:2181 </code></pre> <h3 id="articleHeader13">web.xml配置</h3> <div class="widget-codetool" style="display:none;"> <div class="widget-codetool--inner"> <span class="selectCode code-tool" data-toggle="tooltip" data-placement="top" title="" data-original-title="全选"></span> <span type="button" class="copyCode code-tool" data-toggle="tooltip" data-placement="top" data-clipboard-text="<?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> <web-app data-original-title="复制"></span> </div> </p></div> <pre class="hljs xml"><code><span class="hljs-meta">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">web-app</span> <span class="hljs-attr">>"http://java.sun.com/xml/ns/javaee"</span> <span class="hljs-attr">>"http://www.w3.org/2001/XMLSchema-instance"</span> <span class="hljs-attr">xsi:schemaLocation</span>=<span class="hljs-string">"http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"</span> <span class="hljs-attr">version</span>=<span class="hljs-string">"3.0"</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">context-param</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">param-name</span>&gt;</span>contextConfigLocation<span class="hljs-tag">&lt;/<span class="hljs-name">param-name</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">param-value</span>&gt;</span>classpath:META-INF/spring/*.xml<span class="hljs-tag">&lt;/<span class="hljs-name">param-value</span>&gt;</span> <span class="hljs-tag">&lt;/<span class="hljs-name">context-param</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">context-param</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">param-name</span>&gt;</span>log4jConfigLocation<span class="hljs-tag">&lt;/<span class="hljs-name">param-name</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">param-value</span>&gt;</span>WEB-INF/classes/log4j.xml<span class="hljs-tag">&lt;/<span class="hljs-name">param-value</span>&gt;</span> <span class="hljs-tag">&lt;/<span class="hljs-name">context-param</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">context-param</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">param-name</span>&gt;</span>log4jRefreshInterval<span class="hljs-tag">&lt;/<span class="hljs-name">param-name</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">param-value</span>&gt;</span>60000<span class="hljs-tag">&lt;/<span class="hljs-name">param-value</span>&gt;</span> <span class="hljs-tag">&lt;/<span class="hljs-name">context-param</span>&gt;</span> <span class="hljs-comment">&lt;!--this listener must be defined before the spring listener--&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">listener</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">listener-class</span>&gt;</span>com.alibaba.dubbo.remoting.http.servlet.BootstrapListener<span class="hljs-tag">&lt;/<span class="hljs-name">listener-class</span>&gt;</span> <span class="hljs-tag">&lt;/<span class="hljs-name">listener</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">listener</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">listener-class</span>&gt;</span>org.springframework.web.context.ContextLoaderListener<span class="hljs-tag">&lt;/<span class="hljs-name">listener-class</span>&gt;</span> <span class="hljs-tag">&lt;/<span class="hljs-name">listener</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">listener</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">listener-class</span>&gt;</span>org.springframework.web.util.Log4jConfigListener<span class="hljs-tag">&lt;/<span class="hljs-name">listener-class</span>&gt;</span> <span class="hljs-tag">&lt;/<span class="hljs-name">listener</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">servlet</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">servlet-name</span>&gt;</span>dispatcher<span class="hljs-tag">&lt;/<span class="hljs-name">servlet-name</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">servlet-class</span>&gt;</span>com.alibaba.dubbo.remoting.http.servlet.DispatcherServlet<span class="hljs-tag">&lt;/<span class="hljs-name">servlet-class</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">load-on-startup</span>&gt;</span>1<span class="hljs-tag">&lt;/<span class="hljs-name">load-on-startup</span>&gt;</span> <span class="hljs-tag">&lt;/<span class="hljs-name">servlet</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">servlet-mapping</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">servlet-name</span>&gt;</span>dispatcher<span class="hljs-tag">&lt;/<span class="hljs-name">servlet-name</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">url-pattern</span>&gt;</span>/*<span class="hljs-tag">&lt;/<span class="hljs-name">url-pattern</span>&gt;</span> <span class="hljs-tag">&lt;/<span class="hljs-name">servlet-mapping</span>&gt;</span> <span class="hljs-comment">&lt;!--&lt;servlet&gt; &lt;servlet-name&gt;springServlet&lt;/servlet-name&gt; &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt; &lt;init-param&gt; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; &lt;param-value&gt;classpath:META-INF/spring/*.xml&lt;/param-value&gt; &lt;/init-param&gt; &lt;load-on-startup&gt;1&lt;/load-on-startup&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;springServlet&lt;/servlet-name&gt; &lt;url-pattern&gt;/service/*&lt;/url-pattern&gt; &lt;/servlet-mapping&gt;--&gt;</span> <span class="hljs-tag">&lt;/<span class="hljs-name">web-app</span>&gt;</span></code></pre> <h3 id="articleHeader14">log4j.xml配置</h3> <p>log4j.xml在main/resources/目录下面:</p> <div class="widget-codetool" style="display:none;"> <div class="widget-codetool--inner"> <span class="selectCode code-tool" data-toggle="tooltip" data-placement="top" title="" data-original-title="全选"></span> <span type="button" class="copyCode code-tool" data-toggle="tooltip" data-placement="top" data-clipboard-text="<?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> <!-- - Copyright 1999-2011 Alibaba Group. - - Licensed under the Apache License, Version 2.0 (the &quot;License&quot;); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an &quot;AS IS&quot; BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. --> <!DOCTYPE log4j:configuration SYSTEM &quot;log4j.dtd&quot;> <log4j_configuration data-original-title="复制"></span> </div> </p></div> <pre class="hljs xml"><code><span class="hljs-meta">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</span> <span class="hljs-comment">&lt;!-- - Copyright 1999-2011 Alibaba Group. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. --&gt;</span> <span class="hljs-meta">&lt;!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">log4j:configuration</span> <span class="hljs-attr">>"http://jakarta.apache.org/log4j/"</span> <span class="hljs-attr">debug</span>=<span class="hljs-string">"false"</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">appender</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"CONSOLE"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"org.apache.log4j.ConsoleAppender"</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">layout</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"org.apache.log4j.PatternLayout"</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">param</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"ConversionPattern"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"[%d{dd/MM/yy hh:mm:ss:sss z}] %t %5p %c{2}: %m%n"</span> /&gt;</span> <span class="hljs-tag">&lt;/<span class="hljs-name">layout</span>&gt;</span> <span class="hljs-tag">&lt;/<span class="hljs-name">appender</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">appender</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"rollingFile"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"org.apache.log4j.DailyRollingFileAppender"</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">param</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"File"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"logs/server.log"</span> /&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">param</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"DatePattern"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"'.'yyyy-MM-dd'.log'"</span> /&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">layout</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"org.apache.log4j.PatternLayout"</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">param</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"ConversionPattern"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"[%d{MMdd HH:mm:ss SSS} %-5p] [%t] %c{3} - %m%n"</span> /&gt;</span> <span class="hljs-tag">&lt;/<span class="hljs-name">layout</span>&gt;</span> <span class="hljs-tag">&lt;/<span class="hljs-name">appender</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">root</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">level</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"INFO"</span> /&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">appender-ref</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">"CONSOLE"</span> /&gt;</span> <span class="hljs-comment">&lt;!--&lt;appender-ref ref="rollingFile" /&gt;--&gt;</span> <span class="hljs-tag">&lt;/<span class="hljs-name">root</span>&gt;</span> <span class="hljs-tag">&lt;/<span class="hljs-name">log4j:configuration</span>&gt;</span></code></pre> <h3 id="articleHeader15">&nbsp;配置后的工程基本目录结构</h3> <div class="widget-codetool" style="display:none;"> <div class="widget-codetool--inner"> <span class="selectCode code-tool" data-toggle="tooltip" data-placement="top" title="" data-original-title="全选"></span> <span type="button" class="copyCode code-tool" data-toggle="tooltip" data-placement="top" data-clipboard-text="|____build.gradle |____settings.gradle |____src | |____main | | |____java | | |____resources | | | |____log4j.xml | | | |____META-INF | | | | |____spring | | | | | |____services-config.xml | | |____webapp | | | |____index.jsp | | | |____WEB-INF | | | | |____web.xml | |____test | | |____java | | |____resources" title="" data-original-title="复制"></span> </div> </p></div> <pre class="hljs ruby"><code><span class="hljs-params">|____build.gradle |</span>____settings.gradle <span class="hljs-params">|____src |</span> <span class="hljs-params">|____main |</span> <span class="hljs-params">| |</span>____java <span class="hljs-params">| |</span> <span class="hljs-params">|____resources |</span> <span class="hljs-params">| |</span> <span class="hljs-params">|____log4j.xml |</span> <span class="hljs-params">| |</span> <span class="hljs-params">|____META-INF |</span> <span class="hljs-params">| |</span> <span class="hljs-params">| |</span>____spring <span class="hljs-params">| |</span> <span class="hljs-params">| |</span> <span class="hljs-params">| |</span>____services-config.xml <span class="hljs-params">| |</span> <span class="hljs-params">|____webapp |</span> <span class="hljs-params">| |</span> <span class="hljs-params">|____index.jsp |</span> <span class="hljs-params">| |</span> <span class="hljs-params">|____WEB-INF |</span> <span class="hljs-params">| |</span> <span class="hljs-params">| |</span>____web.xml <span class="hljs-params">| |</span>____test <span class="hljs-params">| |</span> <span class="hljs-params">|____java |</span> <span class="hljs-params">| |</span>____resources</code></pre> <h2 id="articleHeader16">Talk is cheap Show you my code</h2> <p>在项目的main文件夹下面新建几个包:<br />com.web.service (接口)<br />com.web.biz (实现+业务)<br />com.web.repository (dao层)<br />com.web.mapper (db映射mapper)</p> <p>至此,一个完整的项目结构成型。回过头来,修改spring的配置,指明扫描包路径。services-config.xml中的这一句<code>&lt;context:component-scan base-package=""/&gt;</code>替换为<code>&lt;context:component-scan base-package="com.web.*"/&gt;</code>。</p> <p>这个很重要,否则会报错误。</p> <p>现在我们在IDEA中配置tomcat,然后运行一下,应该可以启动了。<br />打印的日志如下:</p> <div class="widget-codetool" style="display:none;"> <div class="widget-codetool--inner"> <span class="selectCode code-tool" data-toggle="tooltip" data-placement="top" title="" data-original-title="全选"></span> <span type="button" class="copyCode code-tool" data-toggle="tooltip" data-placement="top" data-clipboard-text="/Users/zhoujunwen/Documents/software/apache-tomcat-8.0.35/bin/catalina.sh run [2016-05-21 05:46:49,256] Artifact Gradle : Joyven:test : test-demo.war (exploded): Server is not connected. Deploy is not available. 21-May-2016 17:46:51.467 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version: Apache Tomcat/8.0.35 21-May-2016 17:46:51.468 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: May 11 2016 21:57:08 UTC 21-May-2016 17:46:51.469 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number: 8.0.35.0 21-May-2016 17:46:51.469 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Mac OS X 21-May-2016 17:46:51.469 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 10.11.4 21-May-2016 17:46:51.469 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: x86_64 21-May-2016 17:46:51.469 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: /Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/jre 21-May-2016 17:46:51.469 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 1.8.0_91-b14 21-May-2016 17:46:51.469 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation 21-May-2016 17:46:51.469 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: /Users/zhoujunwen/Library/Caches/IntelliJIdea15/tomcat/Unnamed_test 21-May-2016 17:46:51.470 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: /Users/zhoujunwen/Documents/software/apache-tomcat-8.0.35 21-May-2016 17:46:51.471 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/Users/zhoujunwen/Library/Caches/IntelliJIdea15/tomcat/Unnamed_test/conf/logging.properties 21-May-2016 17:46:51.471 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager 21-May-2016 17:46:51.471 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote= 21-May-2016 17:46:51.471 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.port=1099 21-May-2016 17:46:51.471 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.ssl=false 21-May-2016 17:46:51.471 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.authenticate=false 21-May-2016 17:46:51.471 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.rmi.server.hostname=127.0.0.1 21-May-2016 17:46:51.472 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048 21-May-2016 17:46:51.472 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.endorsed.dirs=/Users/zhoujunwen/Documents/software/apache-tomcat-8.0.35/endorsed 21-May-2016 17:46:51.472 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/Users/zhoujunwen/Library/Caches/IntelliJIdea15/tomcat/Unnamed_test 21-May-2016 17:46:51.472 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/Users/zhoujunwen/Documents/software/apache-tomcat-8.0.35 21-May-2016 17:46:51.472 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/Users/zhoujunwen/Documents/software/apache-tomcat-8.0.35/temp 21-May-2016 17:46:51.472 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /Users/zhoujunwen/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:. 21-May-2016 17:46:51.712 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler [&quot;http-nio-8080&quot;] 21-May-2016 17:46:51.827 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read 21-May-2016 17:46:51.833 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler [&quot;ajp-nio-8009&quot;] 21-May-2016 17:46:51.834 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read 21-May-2016 17:46:51.839 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 1559 ms 21-May-2016 17:46:51.913 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service Catalina 21-May-2016 17:46:51.913 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.0.35 21-May-2016 17:46:51.935 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler [&quot;http-nio-8080&quot;] 21-May-2016 17:46:51.947 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler [&quot;ajp-nio-8009&quot;] 21-May-2016 17:46:51.948 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 109 ms Connected to server [2016-05-21 05:46:52,287] Artifact Gradle : Joyven:test : test-demo.war (exploded): Artifact is being deployed, please wait... 21-May-2016 17:46:57.182 INFO [RMI TCP Connection(2)-127.0.0.1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/Users/zhoujunwen/Documents/workspace/java/test-demo/out/artifacts/test/exploded/test-demo.war/WEB-INF/lib/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/Users/zhoujunwen/Documents/workspace/java/test-demo/out/artifacts/test/exploded/test-demo.war/WEB-INF/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory] ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console. [21/05/16 05:46:58:058 CST] RMI TCP Connection(2)-127.0.0.1 INFO logger.LoggerFactory: using logger: com.alibaba.dubbo.common.logger.log4j.Log4jLoggerAdapter [21/05/16 05:46:58:058 CST] RMI TCP Connection(2)-127.0.0.1 ERROR common.Version: [DUBBO] Duplicate class com/alibaba/dubbo/common/Version.class in 2 jar [file:/Users/zhoujunwen/Documents/workspace/java/test-demo/out/artifacts/test/exploded/test-demo.war/WEB-INF/lib/dubbo-2.8.4.jar!/com/alibaba/dubbo/common/Version.class, file:/Users/zhoujunwen/Documents/workspace/java/test-demo/out/artifacts/test/exploded/test-demo.war/WEB-INF/lib/dubbo-common-2.8.4.jar!/com/alibaba/dubbo/common/Version.class], dubbo version: 2.8.4, current host: 127.0.0.1 [21/05/16 05:46:58:058 CST] RMI TCP Connection(2)-127.0.0.1 INFO config.AbstractConfig: [DUBBO] The service ready on spring started. service: com.web.services.TestService, dubbo version: 2.8.4, current host: 127.0.0.1 [21/05/16 05:46:58:058 CST] RMI TCP Connection(2)-127.0.0.1 INFO config.AbstractConfig: [DUBBO] Export dubbo service com.web.services.TestService to local registry, dubbo version: 2.8.4, current host: 127.0.0.1 [21/05/16 05:46:58:058 CST] RMI TCP Connection(2)-127.0.0.1 INFO config.AbstractConfig: [DUBBO] Export dubbo service com.web.services.TestService to url rest://192.168.0.4:8080/test-demo/com.web.services.TestService?accepts=500&amp;anyhost=true&amp;application=test-demo&amp;dubbo=2.8.4&amp;extension=com.alibaba.dubbo.rpc.protocol.rest.support.LoggingFilter&amp;generic=false&amp;interface=com.web.services.TestService&amp;methods=sayHello&amp;organization=freedom&amp;owner=Joyven&amp;pid=1417&amp;server=servlet&amp;side=provider&amp;threads=500&amp;timestamp=1463824018811, dubbo version: 2.8.4, current host: 127.0.0.1 [21/05/16 05:46:58:058 CST] RMI TCP Connection(2)-127.0.0.1 INFO config.AbstractConfig: [DUBBO] Register dubbo service com.web.services.TestService url rest://192.168.0.4:8080/test-demo/com.web.services.TestService?accepts=500&amp;anyhost=true&amp;application=test-demo&amp;dubbo=2.8.4&amp;extension=com.alibaba.dubbo.rpc.protocol.rest.support.LoggingFilter&amp;generic=false&amp;interface=com.web.services.TestService&amp;methods=sayHello&amp;organization=freedom&amp;owner=Joyven&amp;pid=1417&amp;server=servlet&amp;side=provider&amp;threads=500&amp;timestamp=1463824018811 to registry registry://127.0.0.1:2181/com.alibaba.dubbo.registry.RegistryService?application=test-demo&amp;dubbo=2.8.4&amp;organization=freedom&amp;owner=Joyven&amp;pid=1417&amp;registry=zookeeper&amp;timestamp=1463824018795, dubbo version: 2.8.4, current host: 127.0.0.1 [21/05/16 05:46:59:059 CST] RMI TCP Connection(2)-127.0.0.1 INFO zookeeper.ZookeeperRegistry: [DUBBO] Load registry store file /Users/zhoujunwen/.dubbo/dubbo-registry-127.0.0.1.cache, data: {cn.idongjia.tianji.services.NotifyService=empty://10.0.0.24/cn.idongjia.tianji.services.NotifyService?application=dongjia-web-service&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.NotifyService&amp;methods=notifyOne,notifyAll,sms,unregister,notifyList,messageSend,register,checkCode&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355564 empty://10.0.0.24/cn.idongjia.tianji.services.NotifyService?application=dongjia-web-service&amp;category=routers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.NotifyService&amp;methods=notifyOne,notifyAll,sms,unregister,notifyList,messageSend,register,checkCode&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355564 empty://10.0.0.24/cn.idongjia.tianji.services.NotifyService?application=dongjia-web-service&amp;category=providers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.NotifyService&amp;methods=notifyOne,notifyAll,sms,unregister,notifyList,messageSend,register,checkCode&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355564, com.web.services.TestService=empty://192.168.0.4:8080/test-demo/com.web.services.TestService?accepts=500&amp;anyhost=true&amp;application=test-demo&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;extension=com.alibaba.dubbo.rpc.protocol.rest.support.LoggingFilter&amp;generic=false&amp;interface=com.web.services.TestService&amp;methods=sayHello&amp;organization=freedom&amp;owner=Joyven&amp;pid=1376&amp;server=servlet&amp;side=provider&amp;threads=500&amp;timestamp=1463822337491, cn.idongjia.tianji.services.ReturnGoodsService=empty://10.0.0.24/cn.idongjia.tianji.services.ReturnGoodsService?application=dongjia-web-service&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.ReturnGoodsService&amp;methods=cancel,allow,aliNotify,apply,list,confirm,disallow,reject,batchGet,getByOrder,detail,send&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044359264 empty://10.0.0.24/cn.idongjia.tianji.services.ReturnGoodsService?application=dongjia-web-service&amp;category=routers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.ReturnGoodsService&amp;methods=cancel,allow,aliNotify,apply,list,confirm,disallow,reject,batchGet,getByOrder,detail,send&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044359264 empty://10.0.0.24/cn.idongjia.tianji.services.ReturnGoodsService?application=dongjia-web-service&amp;category=providers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.ReturnGoodsService&amp;methods=cancel,allow,aliNotify,apply,list,confirm,disallow,reject,batchGet,getByOrder,detail,send&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044359264, cn.idongjia.tianji.services.BankcardService=empty://10.0.0.24/cn.idongjia.tianji.services.BankcardService?application=dongjia-web-service&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.BankcardService&amp;methods=add,getAll,modifyDefault,get,update,delete,getCount,getUserBankcard&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355819 empty://10.0.0.24/cn.idongjia.tianji.services.BankcardService?application=dongjia-web-service&amp;category=routers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.BankcardService&amp;methods=add,getAll,modifyDefault,get,update,delete,getCount,getUserBankcard&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355819 empty://10.0.0.24/cn.idongjia.tianji.services.BankcardService?application=dongjia-web-service&amp;category=providers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.BankcardService&amp;methods=add,getAll,modifyDefault,get,update,delete,getCount,getUserBankcard&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355819, cn.idongjia.cashout.service.CashoutService=empty://10.0.0.24/cn.idongjia.cashout.service.CashoutService?application=dongjia-web-service&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.cashout.service.CashoutService&amp;methods=execute&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355776 empty://10.0.0.24/cn.idongjia.cashout.service.CashoutService?application=dongjia-web-service&amp;category=routers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.cashout.service.CashoutService&amp;methods=execute&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355776 empty://10.0.0.24/cn.idongjia.cashout.service.CashoutService?application=dongjia-web-service&amp;category=providers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.cashout.service.CashoutService&amp;methods=execute&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355776, cn.idongjia.tianji.services.OrderService=empty://10.0.0.24/cn.idongjia.tianji.services.OrderService?application=dongjia-web-service&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.OrderService&amp;methods=notes,hidden,getDetail,setPayed,searchCount,update,ship,delete,wxNotify,search,inWXPay,get,changeAddress,alipayNotify,close,getCount,payed,add,getAll,pay,confirm,delay,changeRealpay,evaluate&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355881 empty://10.0.0.24/cn.idongjia.tianji.services.OrderService?application=dongjia-web-service&amp;category=routers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.OrderService&amp;methods=notes,hidden,getDetail,setPayed,searchCount,update,ship,delete,wxNotify,search,inWXPay,get,changeAddress,alipayNotify,close,getCount,payed,add,getAll,pay,confirm,delay,changeRealpay,evaluate&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355881 empty://10.0.0.24/cn.idongjia.tianji.services.OrderService?application=dongjia-web-service&amp;category=providers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.OrderService&amp;methods=notes,hidden,getDetail,setPayed,searchCount,update,ship,delete,wxNotify,search,inWXPay,get,changeAddress,alipayNotify,close,getCount,payed,add,getAll,pay,confirm,delay,changeRealpay,evaluate&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355881, cn.idongjia.search.service.QueryService=empty://10.0.0.24/cn.idongjia.search.service.QueryService?application=dongjia-web-service&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.search.service.QueryService&amp;methods=searchCraftsMan,searchItemWithPrice,searchItem&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044359316 empty://10.0.0.24/cn.idongjia.search.service.QueryService?application=dongjia-web-service&amp;category=routers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.search.service.QueryService&amp;methods=searchCraftsMan,searchItemWithPrice,searchItem&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044359316 empty://10.0.0.24/cn.idongjia.search.service.QueryService?application=dongjia-web-service&amp;category=providers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.search.service.QueryService&amp;methods=searchCraftsMan,searchItemWithPrice,searchItem&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044359316, cn.idongjia.tianji.services.ItemService=empty://10.0.0.24/cn.idongjia.tianji.services.ItemService?application=dongjia-web-service&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.ItemService&amp;methods=add,onShelf,getEvaluateCount,getAll,tagItems,getLogs,addAndDown,searchCount,update,getFeed,craftsmans,delete,search,createAuction,getFeeds,offShelf,get,getAuction,addStock,topic,batchGet,getEvaluates,getCount&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355306 empty://10.0.0.24/cn.idongjia.tianji.services.ItemService?application=dongjia-web-service&amp;category=routers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.ItemService&amp;methods=add,onShelf,getEvaluateCount,getAll,tagItems,getLogs,addAndDown,searchCount,update,getFeed,craftsmans,delete,search,createAuction,getFeeds,offShelf,get,getAuction,addStock,topic,batchGet,getEvaluates,getCount&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355306 empty://10.0.0.24/cn.idongjia.tianji.services.ItemService?application=dongjia-web-service&amp;category=providers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.ItemService&amp;methods=add,onShelf,getEvaluateCount,getAll,tagItems,getLogs,addAndDown,searchCount,update,getFeed,craftsmans,delete,search,createAuction,getFeeds,offShelf,get,getAuction,addStock,topic,batchGet,getEvaluates,getCount&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355306, cn.idongjia.auction.api.AuctionService=empty://10.0.0.24/cn.idongjia.auction.api.AuctionService?application=dongjia-web-service&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.auction.api.AuctionService&amp;methods=createAuction,getMaxAuction,getAuctionRecord,getAuction,updateAuction,getAuctionRecordCount,searchAuctionCount,searchAuction&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355418 empty://10.0.0.24/cn.idongjia.auction.api.AuctionService?application=dongjia-web-service&amp;category=routers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.auction.api.AuctionService&amp;methods=createAuction,getMaxAuction,getAuctionRecord,getAuction,updateAuction,getAuctionRecordCount,searchAuctionCount,searchAuction&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355418 empty://10.0.0.24/cn.idongjia.auction.api.AuctionService?application=dongjia-web-service&amp;category=providers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.auction.api.AuctionService&amp;methods=createAuction,getMaxAuction,getAuctionRecord,getAuction,updateAuction,getAuctionRecordCount,searchAuctionCount,searchAuction&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355418, cn.idongjia.tianji.services.AfterSaleService=empty://10.0.0.24/cn.idongjia.tianji.services.AfterSaleService?application=dongjia-web-service&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.AfterSaleService&amp;methods=add,getAll,get,update,delete,getCount&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355478 empty://10.0.0.24/cn.idongjia.tianji.services.AfterSaleService?application=dongjia-web-service&amp;category=routers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.AfterSaleService&amp;methods=add,getAll,get,update,delete,getCount&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355478 empty://10.0.0.24/cn.idongjia.tianji.services.AfterSaleService?application=dongjia-web-service&amp;category=providers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.AfterSaleService&amp;methods=add,getAll,get,update,delete,getCount&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355478, cn.idongjia.tianji.services.AutoTaskService=empty://10.0.0.24/cn.idongjia.tianji.services.AutoTaskService?application=dongjia-web-service&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.AutoTaskService&amp;methods=addCollect&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355958 empty://10.0.0.24/cn.idongjia.tianji.services.AutoTaskService?application=dongjia-web-service&amp;category=routers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.AutoTaskService&amp;methods=addCollect&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355958 empty://10.0.0.24/cn.idongjia.tianji.services.AutoTaskService?application=dongjia-web-service&amp;category=providers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.AutoTaskService&amp;methods=addCollect&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355958, cn.idongjia.kuaidi.services.ShipService=empty://10.0.0.24/cn.idongjia.kuaidi.services.ShipService?application=dongjia-web-service&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.kuaidi.services.ShipService&amp;methods=add,deleteCompany,getCompanies,getAll,getShipment,subscribe,addCompany,update,getMessage,delete,getCount&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044359376 empty://10.0.0.24/cn.idongjia.kuaidi.services.ShipService?application=dongjia-web-service&amp;category=routers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.kuaidi.services.ShipService&amp;methods=add,deleteCompany,getCompanies,getAll,getShipment,subscribe,addCompany,update,getMessage,delete,getCount&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044359376 empty://10.0.0.24/cn.idongjia.kuaidi.services.ShipService?application=dongjia-web-service&amp;category=providers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.kuaidi.services.ShipService&amp;methods=add,deleteCompany,getCompanies,getAll,getShipment,subscribe,addCompany,update,getMessage,delete,getCount&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044359376, cn.idongjia.web.service.VideoViewService=empty://192.168.0.4:8080/presentation/cn.idongjia.web.service.VideoViewService?accepts=500&amp;anyhost=true&amp;application=doangjia-data-presentation&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;extension=com.alibaba.dubbo.rpc.protocol.rest.support.LoggingFilter&amp;generic=false&amp;interface=cn.idongjia.web.service.VideoViewService&amp;methods=getVideoViews,count&amp;organization=dongjia&amp;owner=dongjia&amp;pid=611&amp;server=servlet&amp;side=provider&amp;threads=500&amp;timestamp=1463817345564, cn.idongjia.web.service.PageViewService=empty://192.168.0.4:8080/presentation/cn.idongjia.web.service.PageViewService?accepts=500&amp;anyhost=true&amp;application=doangjia-data-presentation&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;extension=com.alibaba.dubbo.rpc.protocol.rest.support.LoggingFilter&amp;generic=false&amp;interface=cn.idongjia.web.service.PageViewService&amp;methods=getCount,getPageView&amp;organization=dongjia&amp;owner=dongjia&amp;pid=1330&amp;server=servlet&amp;side=provider&amp;threads=500&amp;timestamp=1463822156360, cn.idongjia.web.service.OrderChannelService=empty://192.168.0.4:8080/presentation/cn.idongjia.web.service.OrderChannelService?accepts=500&amp;anyhost=true&amp;application=doangjia-data-presentation&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;extension=com.alibaba.dubbo.rpc.protocol.rest.support.LoggingFilter&amp;generic=false&amp;interface=cn.idongjia.web.service.OrderChannelService&amp;methods=totalCountByOrderInfo,getChannelByOderInfo&amp;organization=dongjia&amp;owner=dongjia&amp;pid=1330&amp;server=servlet&amp;side=provider&amp;threads=500&amp;timestamp=1463822157325, cn.idongjia.web.service.ConversionRateService=empty://192.168.0.4:8080/presentation/cn.idongjia.web.service.ConversionRateService?accepts=500&amp;anyhost=true&amp;application=doangjia-data-presentation&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;extension=com.alibaba.dubbo.rpc.protocol.rest.support.LoggingFilter&amp;generic=false&amp;interface=cn.idongjia.web.service.ConversionRateService&amp;methods=getConversionRateCount,getConversionRate&amp;organization=dongjia&amp;owner=dongjia&amp;pid=611&amp;server=servlet&amp;side=provider&amp;threads=500&amp;timestamp=1463817345675, cn.idongjia.kunwu.service.RiskService=empty://10.0.0.24/cn.idongjia.kunwu.service.RiskService?application=dongjia-web-service&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.kunwu.service.RiskService&amp;methods=execute&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044353160 empty://10.0.0.24/cn.idongjia.kunwu.service.RiskService?application=dongjia-web-service&amp;category=routers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.kunwu.service.RiskService&amp;methods=execute&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044353160 empty://10.0.0.24/cn.idongjia.kunwu.service.RiskService?application=dongjia-web-service&amp;category=providers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.kunwu.service.RiskService&amp;methods=execute&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044353160, cn.idongjia.article.services.ArticleService=empty://10.0.0.24/cn.idongjia.article.services.ArticleService?application=dongjia-web-service&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.article.services.ArticleService&amp;methods=getRecommends,getTabs,getRed,getFeeds,getNewGoodNum,getNewGoodFeeds,getNewGoodTitle,getSearchInfo&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044359189 empty://10.0.0.24/cn.idongjia.article.services.ArticleService?application=dongjia-web-service&amp;category=routers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.article.services.ArticleService&amp;methods=getRecommends,getTabs,getRed,getFeeds,getNewGoodNum,getNewGoodFeeds,getNewGoodTitle,getSearchInfo&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044359189 empty://10.0.0.24/cn.idongjia.article.services.ArticleService?application=dongjia-web-service&amp;category=providers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.article.services.ArticleService&amp;methods=getRecommends,getTabs,getRed,getFeeds,getNewGoodNum,getNewGoodFeeds,getNewGoodTitle,getSearchInfo&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044359189, cn.idongjia.mq.config.MessageQueueService=empty://10.0.0.24/cn.idongjia.mq.config.MessageQueueService?application=dongjia-web-service&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.mq.config.MessageQueueService&amp;methods=getMqConfig&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044356001 empty://10.0.0.24/cn.idongjia.mq.config.MessageQueueService?application=dongjia-web-service&amp;category=routers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.mq.config.MessageQueueService&amp;methods=getMqConfig&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044356001 empty://10.0.0.24/cn.idongjia.mq.config.MessageQueueService?application=dongjia-web-service&amp;category=providers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.mq.config.MessageQueueService&amp;methods=getMqConfig&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044356001, cn.idongjia.tianji.services.UserMergeService=empty://10.0.0.24/cn.idongjia.tianji.services.UserMergeService?application=dongjia-web-service&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.UserMergeService&amp;methods=mergeAll,mergeByUid,isWxLogin,ifNeedMerge,merge&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044359443 empty://10.0.0.24/cn.idongjia.tianji.services.UserMergeService?application=dongjia-web-service&amp;category=routers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.UserMergeService&amp;methods=mergeAll,mergeByUid,isWxLogin,ifNeedMerge,merge&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044359443 empty://10.0.0.24/cn.idongjia.tianji.services.UserMergeService?application=dongjia-web-service&amp;category=providers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.UserMergeService&amp;methods=mergeAll,mergeByUid,isWxLogin,ifNeedMerge,merge&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044359443}, dubbo version: 2.8.4, current host: 127.0.0.1 [21/05/16 05:46:59:059 CST] ZkClient-EventThread-39-127.0.0.1:2181 INFO zkclient.ZkEventThread: Starting ZkClient event thread. [21/05/16 05:46:59:059 CST] RMI TCP Connection(2)-127.0.0.1-EventThread INFO zkclient.ZkClient: zookeeper state changed (SyncConnected) [21/05/16 05:46:59:059 CST] RMI TCP Connection(2)-127.0.0.1 INFO zookeeper.ZookeeperRegistry: [DUBBO] Register: rest://192.168.0.4:8080/test-demo/com.web.services.TestService?accepts=500&amp;anyhost=true&amp;application=test-demo&amp;dubbo=2.8.4&amp;extension=com.alibaba.dubbo.rpc.protocol.rest.support.LoggingFilter&amp;generic=false&amp;interface=com.web.services.TestService&amp;methods=sayHello&amp;organization=freedom&amp;owner=Joyven&amp;pid=1417&amp;server=servlet&amp;side=provider&amp;threads=500&amp;timestamp=1463824018811, dubbo version: 2.8.4, current host: 127.0.0.1 [21/05/16 05:46:59:059 CST] RMI TCP Connection(2)-127.0.0.1 INFO zookeeper.ZookeeperRegistry: [DUBBO] Subscribe: provider://192.168.0.4:8080/test-demo/com.web.services.TestService?accepts=500&amp;anyhost=true&amp;application=test-demo&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;extension=com.alibaba.dubbo.rpc.protocol.rest.support.LoggingFilter&amp;generic=false&amp;interface=com.web.services.TestService&amp;methods=sayHello&amp;organization=freedom&amp;owner=Joyven&amp;pid=1417&amp;server=servlet&amp;side=provider&amp;threads=500&amp;timestamp=1463824018811, dubbo version: 2.8.4, current host: 127.0.0.1 [21/05/16 05:46:59:059 CST] RMI TCP Connection(2)-127.0.0.1 INFO zookeeper.ZookeeperRegistry: [DUBBO] Notify urls for subscribe url provider://192.168.0.4:8080/test-demo/com.web.services.TestService?accepts=500&amp;anyhost=true&amp;application=test-demo&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;extension=com.alibaba.dubbo.rpc.protocol.rest.support.LoggingFilter&amp;generic=false&amp;interface=com.web.services.TestService&amp;methods=sayHello&amp;organization=freedom&amp;owner=Joyven&amp;pid=1417&amp;server=servlet&amp;side=provider&amp;threads=500&amp;timestamp=1463824018811, urls: [empty://192.168.0.4:8080/test-demo/com.web.services.TestService?accepts=500&amp;anyhost=true&amp;application=test-demo&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;extension=com.alibaba.dubbo.rpc.protocol.rest.support.LoggingFilter&amp;generic=false&amp;interface=com.web.services.TestService&amp;methods=sayHello&amp;organization=freedom&amp;owner=Joyven&amp;pid=1417&amp;server=servlet&amp;side=provider&amp;threads=500&amp;timestamp=1463824018811], dubbo version: 2.8.4, current host: 127.0.0.1 [2016-05-21 05:46:59,636] Artifact Gradle : Joyven:test : test-demo.war (exploded): Artifact is deployed successfully [2016-05-21 05:46:59,637] Artifact Gradle : Joyven:test : test-demo.war (exploded): Deploy took 7,350 milliseconds [21/05/16 05:47:00:000 CST] http-nio-8080-exec-1 WARN core.ExceptionHandler: failed to execute javax.ws.rs.NotFoundException: Could not find resource for full path: http://localhost:8080// at org.jboss.resteasy.core.registry.ClassNode.match(ClassNode.java:73) at org.jboss.resteasy.core.registry.RootClassNode.match(RootClassNode.java:48) at org.jboss.resteasy.core.ResourceMethodRegistry.getResourceInvoker(ResourceMethodRegistry.java:444)" title="" data-original-title="复制"></span> </div> </p></div> <pre><code>/Users/zhoujunwen/Documents/software/apache-tomcat-8.0.35/bin/catalina.sh run [2016-05-21 05:46:49,256] Artifact Gradle : Joyven:test : test-demo.war (exploded): Server is not connected. Deploy is not available. 21-May-2016 17:46:51.467 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version: Apache Tomcat/8.0.35 21-May-2016 17:46:51.468 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: May 11 2016 21:57:08 UTC 21-May-2016 17:46:51.469 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number: 8.0.35.0 21-May-2016 17:46:51.469 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Mac OS X 21-May-2016 17:46:51.469 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 10.11.4 21-May-2016 17:46:51.469 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: x86_64 21-May-2016 17:46:51.469 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: /Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/jre 21-May-2016 17:46:51.469 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 1.8.0_91-b14 21-May-2016 17:46:51.469 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation 21-May-2016 17:46:51.469 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: /Users/zhoujunwen/Library/Caches/IntelliJIdea15/tomcat/Unnamed_test 21-May-2016 17:46:51.470 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: /Users/zhoujunwen/Documents/software/apache-tomcat-8.0.35 21-May-2016 17:46:51.471 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/Users/zhoujunwen/Library/Caches/IntelliJIdea15/tomcat/Unnamed_test/conf/logging.properties 21-May-2016 17:46:51.471 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager 21-May-2016 17:46:51.471 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote= 21-May-2016 17:46:51.471 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.port=1099 21-May-2016 17:46:51.471 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.ssl=false 21-May-2016 17:46:51.471 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.authenticate=false 21-May-2016 17:46:51.471 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.rmi.server.hostname=127.0.0.1 21-May-2016 17:46:51.472 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048 21-May-2016 17:46:51.472 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.endorsed.dirs=/Users/zhoujunwen/Documents/software/apache-tomcat-8.0.35/endorsed 21-May-2016 17:46:51.472 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/Users/zhoujunwen/Library/Caches/IntelliJIdea15/tomcat/Unnamed_test 21-May-2016 17:46:51.472 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/Users/zhoujunwen/Documents/software/apache-tomcat-8.0.35 21-May-2016 17:46:51.472 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/Users/zhoujunwen/Documents/software/apache-tomcat-8.0.35/temp 21-May-2016 17:46:51.472 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /Users/zhoujunwen/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:. 21-May-2016 17:46:51.712 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"] 21-May-2016 17:46:51.827 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read 21-May-2016 17:46:51.833 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"] 21-May-2016 17:46:51.834 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read 21-May-2016 17:46:51.839 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 1559 ms 21-May-2016 17:46:51.913 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service Catalina 21-May-2016 17:46:51.913 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.0.35 21-May-2016 17:46:51.935 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"] 21-May-2016 17:46:51.947 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"] 21-May-2016 17:46:51.948 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 109 ms Connected to server [2016-05-21 05:46:52,287] Artifact Gradle : Joyven:test : test-demo.war (exploded): Artifact is being deployed, please wait... 21-May-2016 17:46:57.182 INFO [RMI TCP Connection(2)-127.0.0.1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/Users/zhoujunwen/Documents/workspace/java/test-demo/out/artifacts/test/exploded/test-demo.war/WEB-INF/lib/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/Users/zhoujunwen/Documents/workspace/java/test-demo/out/artifacts/test/exploded/test-demo.war/WEB-INF/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory] ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console. [21/05/16 05:46:58:058 CST] RMI TCP Connection(2)-127.0.0.1 INFO logger.LoggerFactory: using logger: com.alibaba.dubbo.common.logger.log4j.Log4jLoggerAdapter [21/05/16 05:46:58:058 CST] RMI TCP Connection(2)-127.0.0.1 ERROR common.Version: [DUBBO] Duplicate class com/alibaba/dubbo/common/Version.class in 2 jar [file:/Users/zhoujunwen/Documents/workspace/java/test-demo/out/artifacts/test/exploded/test-demo.war/WEB-INF/lib/dubbo-2.8.4.jar!/com/alibaba/dubbo/common/Version.class, file:/Users/zhoujunwen/Documents/workspace/java/test-demo/out/artifacts/test/exploded/test-demo.war/WEB-INF/lib/dubbo-common-2.8.4.jar!/com/alibaba/dubbo/common/Version.class], dubbo version: 2.8.4, current host: 127.0.0.1 [21/05/16 05:46:58:058 CST] RMI TCP Connection(2)-127.0.0.1 INFO config.AbstractConfig: [DUBBO] The service ready on spring started. service: com.web.services.TestService, dubbo version: 2.8.4, current host: 127.0.0.1 [21/05/16 05:46:58:058 CST] RMI TCP Connection(2)-127.0.0.1 INFO config.AbstractConfig: [DUBBO] Export dubbo service com.web.services.TestService to local registry, dubbo version: 2.8.4, current host: 127.0.0.1 [21/05/16 05:46:58:058 CST] RMI TCP Connection(2)-127.0.0.1 INFO config.AbstractConfig: [DUBBO] Export dubbo service com.web.services.TestService to url rest://192.168.0.4:8080/test-demo/com.web.services.TestService?accepts=500&amp;anyhost=true&amp;application=test-demo&amp;dubbo=2.8.4&amp;extension=com.alibaba.dubbo.rpc.protocol.rest.support.LoggingFilter&amp;generic=false&amp;interface=com.web.services.TestService&amp;methods=sayHello&amp;organization=freedom&amp;owner=Joyven&amp;pid=1417&amp;server=servlet&amp;side=provider&amp;threads=500&amp;timestamp=1463824018811, dubbo version: 2.8.4, current host: 127.0.0.1 [21/05/16 05:46:58:058 CST] RMI TCP Connection(2)-127.0.0.1 INFO config.AbstractConfig: [DUBBO] Register dubbo service com.web.services.TestService url rest://192.168.0.4:8080/test-demo/com.web.services.TestService?accepts=500&amp;anyhost=true&amp;application=test-demo&amp;dubbo=2.8.4&amp;extension=com.alibaba.dubbo.rpc.protocol.rest.support.LoggingFilter&amp;generic=false&amp;interface=com.web.services.TestService&amp;methods=sayHello&amp;organization=freedom&amp;owner=Joyven&amp;pid=1417&amp;server=servlet&amp;side=provider&amp;threads=500&amp;timestamp=1463824018811 to registry registry://127.0.0.1:2181/com.alibaba.dubbo.registry.RegistryService?application=test-demo&amp;dubbo=2.8.4&amp;organization=freedom&amp;owner=Joyven&amp;pid=1417&amp;registry=zookeeper&amp;timestamp=1463824018795, dubbo version: 2.8.4, current host: 127.0.0.1 [21/05/16 05:46:59:059 CST] RMI TCP Connection(2)-127.0.0.1 INFO zookeeper.ZookeeperRegistry: [DUBBO] Load registry store file /Users/zhoujunwen/.dubbo/dubbo-registry-127.0.0.1.cache, data: {cn.idongjia.tianji.services.NotifyService=empty://10.0.0.24/cn.idongjia.tianji.services.NotifyService?application=dongjia-web-service&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.NotifyService&amp;methods=notifyOne,notifyAll,sms,unregister,notifyList,messageSend,register,checkCode&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355564 empty://10.0.0.24/cn.idongjia.tianji.services.NotifyService?application=dongjia-web-service&amp;category=routers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.NotifyService&amp;methods=notifyOne,notifyAll,sms,unregister,notifyList,messageSend,register,checkCode&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355564 empty://10.0.0.24/cn.idongjia.tianji.services.NotifyService?application=dongjia-web-service&amp;category=providers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.NotifyService&amp;methods=notifyOne,notifyAll,sms,unregister,notifyList,messageSend,register,checkCode&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355564, com.web.services.TestService=empty://192.168.0.4:8080/test-demo/com.web.services.TestService?accepts=500&amp;anyhost=true&amp;application=test-demo&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;extension=com.alibaba.dubbo.rpc.protocol.rest.support.LoggingFilter&amp;generic=false&amp;interface=com.web.services.TestService&amp;methods=sayHello&amp;organization=freedom&amp;owner=Joyven&amp;pid=1376&amp;server=servlet&amp;side=provider&amp;threads=500&amp;timestamp=1463822337491, cn.idongjia.tianji.services.ReturnGoodsService=empty://10.0.0.24/cn.idongjia.tianji.services.ReturnGoodsService?application=dongjia-web-service&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.ReturnGoodsService&amp;methods=cancel,allow,aliNotify,apply,list,confirm,disallow,reject,batchGet,getByOrder,detail,send&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044359264 empty://10.0.0.24/cn.idongjia.tianji.services.ReturnGoodsService?application=dongjia-web-service&amp;category=routers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.ReturnGoodsService&amp;methods=cancel,allow,aliNotify,apply,list,confirm,disallow,reject,batchGet,getByOrder,detail,send&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044359264 empty://10.0.0.24/cn.idongjia.tianji.services.ReturnGoodsService?application=dongjia-web-service&amp;category=providers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.ReturnGoodsService&amp;methods=cancel,allow,aliNotify,apply,list,confirm,disallow,reject,batchGet,getByOrder,detail,send&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044359264, cn.idongjia.tianji.services.BankcardService=empty://10.0.0.24/cn.idongjia.tianji.services.BankcardService?application=dongjia-web-service&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.BankcardService&amp;methods=add,getAll,modifyDefault,get,update,delete,getCount,getUserBankcard&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355819 empty://10.0.0.24/cn.idongjia.tianji.services.BankcardService?application=dongjia-web-service&amp;category=routers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.BankcardService&amp;methods=add,getAll,modifyDefault,get,update,delete,getCount,getUserBankcard&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355819 empty://10.0.0.24/cn.idongjia.tianji.services.BankcardService?application=dongjia-web-service&amp;category=providers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.BankcardService&amp;methods=add,getAll,modifyDefault,get,update,delete,getCount,getUserBankcard&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355819, cn.idongjia.cashout.service.CashoutService=empty://10.0.0.24/cn.idongjia.cashout.service.CashoutService?application=dongjia-web-service&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.cashout.service.CashoutService&amp;methods=execute&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355776 empty://10.0.0.24/cn.idongjia.cashout.service.CashoutService?application=dongjia-web-service&amp;category=routers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.cashout.service.CashoutService&amp;methods=execute&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355776 empty://10.0.0.24/cn.idongjia.cashout.service.CashoutService?application=dongjia-web-service&amp;category=providers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.cashout.service.CashoutService&amp;methods=execute&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355776, cn.idongjia.tianji.services.OrderService=empty://10.0.0.24/cn.idongjia.tianji.services.OrderService?application=dongjia-web-service&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.OrderService&amp;methods=notes,hidden,getDetail,setPayed,searchCount,update,ship,delete,wxNotify,search,inWXPay,get,changeAddress,alipayNotify,close,getCount,payed,add,getAll,pay,confirm,delay,changeRealpay,evaluate&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355881 empty://10.0.0.24/cn.idongjia.tianji.services.OrderService?application=dongjia-web-service&amp;category=routers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.OrderService&amp;methods=notes,hidden,getDetail,setPayed,searchCount,update,ship,delete,wxNotify,search,inWXPay,get,changeAddress,alipayNotify,close,getCount,payed,add,getAll,pay,confirm,delay,changeRealpay,evaluate&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355881 empty://10.0.0.24/cn.idongjia.tianji.services.OrderService?application=dongjia-web-service&amp;category=providers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.OrderService&amp;methods=notes,hidden,getDetail,setPayed,searchCount,update,ship,delete,wxNotify,search,inWXPay,get,changeAddress,alipayNotify,close,getCount,payed,add,getAll,pay,confirm,delay,changeRealpay,evaluate&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355881, cn.idongjia.search.service.QueryService=empty://10.0.0.24/cn.idongjia.search.service.QueryService?application=dongjia-web-service&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.search.service.QueryService&amp;methods=searchCraftsMan,searchItemWithPrice,searchItem&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044359316 empty://10.0.0.24/cn.idongjia.search.service.QueryService?application=dongjia-web-service&amp;category=routers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.search.service.QueryService&amp;methods=searchCraftsMan,searchItemWithPrice,searchItem&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044359316 empty://10.0.0.24/cn.idongjia.search.service.QueryService?application=dongjia-web-service&amp;category=providers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.search.service.QueryService&amp;methods=searchCraftsMan,searchItemWithPrice,searchItem&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044359316, cn.idongjia.tianji.services.ItemService=empty://10.0.0.24/cn.idongjia.tianji.services.ItemService?application=dongjia-web-service&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.ItemService&amp;methods=add,onShelf,getEvaluateCount,getAll,tagItems,getLogs,addAndDown,searchCount,update,getFeed,craftsmans,delete,search,createAuction,getFeeds,offShelf,get,getAuction,addStock,topic,batchGet,getEvaluates,getCount&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355306 empty://10.0.0.24/cn.idongjia.tianji.services.ItemService?application=dongjia-web-service&amp;category=routers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.ItemService&amp;methods=add,onShelf,getEvaluateCount,getAll,tagItems,getLogs,addAndDown,searchCount,update,getFeed,craftsmans,delete,search,createAuction,getFeeds,offShelf,get,getAuction,addStock,topic,batchGet,getEvaluates,getCount&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355306 empty://10.0.0.24/cn.idongjia.tianji.services.ItemService?application=dongjia-web-service&amp;category=providers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.ItemService&amp;methods=add,onShelf,getEvaluateCount,getAll,tagItems,getLogs,addAndDown,searchCount,update,getFeed,craftsmans,delete,search,createAuction,getFeeds,offShelf,get,getAuction,addStock,topic,batchGet,getEvaluates,getCount&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355306, cn.idongjia.auction.api.AuctionService=empty://10.0.0.24/cn.idongjia.auction.api.AuctionService?application=dongjia-web-service&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.auction.api.AuctionService&amp;methods=createAuction,getMaxAuction,getAuctionRecord,getAuction,updateAuction,getAuctionRecordCount,searchAuctionCount,searchAuction&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355418 empty://10.0.0.24/cn.idongjia.auction.api.AuctionService?application=dongjia-web-service&amp;category=routers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.auction.api.AuctionService&amp;methods=createAuction,getMaxAuction,getAuctionRecord,getAuction,updateAuction,getAuctionRecordCount,searchAuctionCount,searchAuction&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355418 empty://10.0.0.24/cn.idongjia.auction.api.AuctionService?application=dongjia-web-service&amp;category=providers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.auction.api.AuctionService&amp;methods=createAuction,getMaxAuction,getAuctionRecord,getAuction,updateAuction,getAuctionRecordCount,searchAuctionCount,searchAuction&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355418, cn.idongjia.tianji.services.AfterSaleService=empty://10.0.0.24/cn.idongjia.tianji.services.AfterSaleService?application=dongjia-web-service&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.AfterSaleService&amp;methods=add,getAll,get,update,delete,getCount&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355478 empty://10.0.0.24/cn.idongjia.tianji.services.AfterSaleService?application=dongjia-web-service&amp;category=routers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.AfterSaleService&amp;methods=add,getAll,get,update,delete,getCount&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355478 empty://10.0.0.24/cn.idongjia.tianji.services.AfterSaleService?application=dongjia-web-service&amp;category=providers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.AfterSaleService&amp;methods=add,getAll,get,update,delete,getCount&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355478, cn.idongjia.tianji.services.AutoTaskService=empty://10.0.0.24/cn.idongjia.tianji.services.AutoTaskService?application=dongjia-web-service&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.AutoTaskService&amp;methods=addCollect&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355958 empty://10.0.0.24/cn.idongjia.tianji.services.AutoTaskService?application=dongjia-web-service&amp;category=routers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.AutoTaskService&amp;methods=addCollect&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355958 empty://10.0.0.24/cn.idongjia.tianji.services.AutoTaskService?application=dongjia-web-service&amp;category=providers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.AutoTaskService&amp;methods=addCollect&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044355958, cn.idongjia.kuaidi.services.ShipService=empty://10.0.0.24/cn.idongjia.kuaidi.services.ShipService?application=dongjia-web-service&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.kuaidi.services.ShipService&amp;methods=add,deleteCompany,getCompanies,getAll,getShipment,subscribe,addCompany,update,getMessage,delete,getCount&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044359376 empty://10.0.0.24/cn.idongjia.kuaidi.services.ShipService?application=dongjia-web-service&amp;category=routers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.kuaidi.services.ShipService&amp;methods=add,deleteCompany,getCompanies,getAll,getShipment,subscribe,addCompany,update,getMessage,delete,getCount&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044359376 empty://10.0.0.24/cn.idongjia.kuaidi.services.ShipService?application=dongjia-web-service&amp;category=providers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.kuaidi.services.ShipService&amp;methods=add,deleteCompany,getCompanies,getAll,getShipment,subscribe,addCompany,update,getMessage,delete,getCount&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044359376, cn.idongjia.web.service.VideoViewService=empty://192.168.0.4:8080/presentation/cn.idongjia.web.service.VideoViewService?accepts=500&amp;anyhost=true&amp;application=doangjia-data-presentation&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;extension=com.alibaba.dubbo.rpc.protocol.rest.support.LoggingFilter&amp;generic=false&amp;interface=cn.idongjia.web.service.VideoViewService&amp;methods=getVideoViews,count&amp;organization=dongjia&amp;owner=dongjia&amp;pid=611&amp;server=servlet&amp;side=provider&amp;threads=500&amp;timestamp=1463817345564, cn.idongjia.web.service.PageViewService=empty://192.168.0.4:8080/presentation/cn.idongjia.web.service.PageViewService?accepts=500&amp;anyhost=true&amp;application=doangjia-data-presentation&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;extension=com.alibaba.dubbo.rpc.protocol.rest.support.LoggingFilter&amp;generic=false&amp;interface=cn.idongjia.web.service.PageViewService&amp;methods=getCount,getPageView&amp;organization=dongjia&amp;owner=dongjia&amp;pid=1330&amp;server=servlet&amp;side=provider&amp;threads=500&amp;timestamp=1463822156360, cn.idongjia.web.service.OrderChannelService=empty://192.168.0.4:8080/presentation/cn.idongjia.web.service.OrderChannelService?accepts=500&amp;anyhost=true&amp;application=doangjia-data-presentation&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;extension=com.alibaba.dubbo.rpc.protocol.rest.support.LoggingFilter&amp;generic=false&amp;interface=cn.idongjia.web.service.OrderChannelService&amp;methods=totalCountByOrderInfo,getChannelByOderInfo&amp;organization=dongjia&amp;owner=dongjia&amp;pid=1330&amp;server=servlet&amp;side=provider&amp;threads=500&amp;timestamp=1463822157325, cn.idongjia.web.service.ConversionRateService=empty://192.168.0.4:8080/presentation/cn.idongjia.web.service.ConversionRateService?accepts=500&amp;anyhost=true&amp;application=doangjia-data-presentation&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;extension=com.alibaba.dubbo.rpc.protocol.rest.support.LoggingFilter&amp;generic=false&amp;interface=cn.idongjia.web.service.ConversionRateService&amp;methods=getConversionRateCount,getConversionRate&amp;organization=dongjia&amp;owner=dongjia&amp;pid=611&amp;server=servlet&amp;side=provider&amp;threads=500&amp;timestamp=1463817345675, cn.idongjia.kunwu.service.RiskService=empty://10.0.0.24/cn.idongjia.kunwu.service.RiskService?application=dongjia-web-service&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.kunwu.service.RiskService&amp;methods=execute&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044353160 empty://10.0.0.24/cn.idongjia.kunwu.service.RiskService?application=dongjia-web-service&amp;category=routers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.kunwu.service.RiskService&amp;methods=execute&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044353160 empty://10.0.0.24/cn.idongjia.kunwu.service.RiskService?application=dongjia-web-service&amp;category=providers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.kunwu.service.RiskService&amp;methods=execute&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044353160, cn.idongjia.article.services.ArticleService=empty://10.0.0.24/cn.idongjia.article.services.ArticleService?application=dongjia-web-service&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.article.services.ArticleService&amp;methods=getRecommends,getTabs,getRed,getFeeds,getNewGoodNum,getNewGoodFeeds,getNewGoodTitle,getSearchInfo&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044359189 empty://10.0.0.24/cn.idongjia.article.services.ArticleService?application=dongjia-web-service&amp;category=routers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.article.services.ArticleService&amp;methods=getRecommends,getTabs,getRed,getFeeds,getNewGoodNum,getNewGoodFeeds,getNewGoodTitle,getSearchInfo&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044359189 empty://10.0.0.24/cn.idongjia.article.services.ArticleService?application=dongjia-web-service&amp;category=providers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.article.services.ArticleService&amp;methods=getRecommends,getTabs,getRed,getFeeds,getNewGoodNum,getNewGoodFeeds,getNewGoodTitle,getSearchInfo&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044359189, cn.idongjia.mq.config.MessageQueueService=empty://10.0.0.24/cn.idongjia.mq.config.MessageQueueService?application=dongjia-web-service&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.mq.config.MessageQueueService&amp;methods=getMqConfig&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044356001 empty://10.0.0.24/cn.idongjia.mq.config.MessageQueueService?application=dongjia-web-service&amp;category=routers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.mq.config.MessageQueueService&amp;methods=getMqConfig&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044356001 empty://10.0.0.24/cn.idongjia.mq.config.MessageQueueService?application=dongjia-web-service&amp;category=providers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.mq.config.MessageQueueService&amp;methods=getMqConfig&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044356001, cn.idongjia.tianji.services.UserMergeService=empty://10.0.0.24/cn.idongjia.tianji.services.UserMergeService?application=dongjia-web-service&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.UserMergeService&amp;methods=mergeAll,mergeByUid,isWxLogin,ifNeedMerge,merge&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044359443 empty://10.0.0.24/cn.idongjia.tianji.services.UserMergeService?application=dongjia-web-service&amp;category=routers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.UserMergeService&amp;methods=mergeAll,mergeByUid,isWxLogin,ifNeedMerge,merge&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044359443 empty://10.0.0.24/cn.idongjia.tianji.services.UserMergeService?application=dongjia-web-service&amp;category=providers&amp;check=false&amp;dubbo=2.8.4&amp;interface=cn.idongjia.tianji.services.UserMergeService&amp;methods=mergeAll,mergeByUid,isWxLogin,ifNeedMerge,merge&amp;organization=dongjia&amp;owner=dongjia&amp;pid=27456&amp;revision=1.2.3-63111df&amp;side=consumer&amp;timestamp=1463044359443}, dubbo version: 2.8.4, current host: 127.0.0.1 [21/05/16 05:46:59:059 CST] ZkClient-EventThread-39-127.0.0.1:2181 INFO zkclient.ZkEventThread: Starting ZkClient event thread. [21/05/16 05:46:59:059 CST] RMI TCP Connection(2)-127.0.0.1-EventThread INFO zkclient.ZkClient: zookeeper state changed (SyncConnected) [21/05/16 05:46:59:059 CST] RMI TCP Connection(2)-127.0.0.1 INFO zookeeper.ZookeeperRegistry: [DUBBO] Register: rest://192.168.0.4:8080/test-demo/com.web.services.TestService?accepts=500&amp;anyhost=true&amp;application=test-demo&amp;dubbo=2.8.4&amp;extension=com.alibaba.dubbo.rpc.protocol.rest.support.LoggingFilter&amp;generic=false&amp;interface=com.web.services.TestService&amp;methods=sayHello&amp;organization=freedom&amp;owner=Joyven&amp;pid=1417&amp;server=servlet&amp;side=provider&amp;threads=500&amp;timestamp=1463824018811, dubbo version: 2.8.4, current host: 127.0.0.1 [21/05/16 05:46:59:059 CST] RMI TCP Connection(2)-127.0.0.1 INFO zookeeper.ZookeeperRegistry: [DUBBO] Subscribe: provider://192.168.0.4:8080/test-demo/com.web.services.TestService?accepts=500&amp;anyhost=true&amp;application=test-demo&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;extension=com.alibaba.dubbo.rpc.protocol.rest.support.LoggingFilter&amp;generic=false&amp;interface=com.web.services.TestService&amp;methods=sayHello&amp;organization=freedom&amp;owner=Joyven&amp;pid=1417&amp;server=servlet&amp;side=provider&amp;threads=500&amp;timestamp=1463824018811, dubbo version: 2.8.4, current host: 127.0.0.1 [21/05/16 05:46:59:059 CST] RMI TCP Connection(2)-127.0.0.1 INFO zookeeper.ZookeeperRegistry: [DUBBO] Notify urls for subscribe url provider://192.168.0.4:8080/test-demo/com.web.services.TestService?accepts=500&amp;anyhost=true&amp;application=test-demo&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;extension=com.alibaba.dubbo.rpc.protocol.rest.support.LoggingFilter&amp;generic=false&amp;interface=com.web.services.TestService&amp;methods=sayHello&amp;organization=freedom&amp;owner=Joyven&amp;pid=1417&amp;server=servlet&amp;side=provider&amp;threads=500&amp;timestamp=1463824018811, urls: [empty://192.168.0.4:8080/test-demo/com.web.services.TestService?accepts=500&amp;anyhost=true&amp;application=test-demo&amp;category=configurators&amp;check=false&amp;dubbo=2.8.4&amp;extension=com.alibaba.dubbo.rpc.protocol.rest.support.LoggingFilter&amp;generic=false&amp;interface=com.web.services.TestService&amp;methods=sayHello&amp;organization=freedom&amp;owner=Joyven&amp;pid=1417&amp;server=servlet&amp;side=provider&amp;threads=500&amp;timestamp=1463824018811], dubbo version: 2.8.4, current host: 127.0.0.1 [2016-05-21 05:46:59,636] Artifact Gradle : Joyven:test : test-demo.war (exploded): Artifact is deployed successfully [2016-05-21 05:46:59,637] Artifact Gradle : Joyven:test : test-demo.war (exploded): Deploy took 7,350 milliseconds [21/05/16 05:47:00:000 CST] http-nio-8080-exec-1 WARN core.ExceptionHandler: failed to execute javax.ws.rs.NotFoundException: Could not find resource for full path: http://localhost:8080// at org.jboss.resteasy.core.registry.ClassNode.match(ClassNode.java:73) at org.jboss.resteasy.core.registry.RootClassNode.match(RootClassNode.java:48) at org.jboss.resteasy.core.ResourceMethodRegistry.getResourceInvoker(ResourceMethodRegistry.java:444)</code></pre> <p>有一个错误,说的是<a href="http://localhost" rel="nofollow noreferrer" target="_blank">http://localhost</a>:8080/找不到,因为我们的请求路径在web.xml中做了过滤,不支持这种请求,它必须是service中的@path指定的路由。</p> <p>先跑一个demo:</p> <ul> <li>com.web.service/TestService.java</li> </ul> <div class="widget-codetool" style="display:none;"> <div class="widget-codetool--inner"> <span class="selectCode code-tool" data-toggle="tooltip" data-placement="top" title="" data-original-title="全选"></span> <span type="button" class="copyCode code-tool" data-toggle="tooltip" data-placement="top" data-clipboard-text="package com.web.service; import java.util.List; /** * Created by zhoujunwen on 16/5/21. */ public interface TestService { List sayHello(); } " title="" data-original-title="复制"></span> </div> </p></div> <pre class="hljs java"><code><span class="hljs-keyword">package</span> com.web.service; <span class="hljs-keyword">import</span> java.util.List; <span class="hljs-comment">/** * Created by zhoujunwen on 16/5/21. */</span> <span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">interface</span> <span class="hljs-title">TestService</span> </span>{ <span class="hljs-function">List <span class="hljs-title">sayHello</span><span class="hljs-params">()</span></span>; } </code></pre> <ul> <li>com.web.biz/TestServiceImpl.java</li> </ul> <div class="widget-codetool" style="display:none;"> <div class="widget-codetool--inner"> <span class="selectCode code-tool" data-toggle="tooltip" data-placement="top" title="" data-original-title="全选"></span> <span type="button" class="copyCode code-tool" data-toggle="tooltip" data-placement="top" data-clipboard-text="package com.web.biz; import com.alibaba.dubbo.rpc.protocol.rest.support.ContentType; import com.web.service.TestService; import org.springframework.stereotype.Component; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import java.util.ArrayList; import java.util.List; @Component(&quot;testService&quot;) @Path(&quot;test&quot;) @Produces({ContentType.APPLICATION_JSON_UTF_8}) public class TestServiceImpl implements TestService { @Override @GET @Path(&quot;say&quot;) public List sayHello() { List list = new ArrayList<>(); list.add(&quot;I am a test service&quot;); return list; } } " title="" data-original-title="复制"></span> </div> </p></div> <pre class="hljs kotlin"><code><span class="hljs-keyword">package</span> com.web.biz; <span class="hljs-keyword">import</span> com.alibaba.dubbo.rpc.protocol.rest.support.ContentType; <span class="hljs-keyword">import</span> com.web.service.TestService; <span class="hljs-keyword">import</span> org.springframework.stereotype.Component; <span class="hljs-keyword">import</span> javax.ws.rs.GET; <span class="hljs-keyword">import</span> javax.ws.rs.Path; <span class="hljs-keyword">import</span> javax.ws.rs.Produces; <span class="hljs-keyword">import</span> java.util.ArrayList; <span class="hljs-keyword">import</span> java.util.List; <span class="hljs-meta">@Component(<span class="hljs-meta-string">"testService"</span>)</span> <span class="hljs-meta">@Path(<span class="hljs-meta-string">"test"</span>)</span> <span class="hljs-meta">@Produces({ContentType.APPLICATION_JSON_UTF_8})</span> <span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">TestServiceImpl</span> <span class="hljs-title">implements</span> <span class="hljs-title">TestService</span> </span>{ <span class="hljs-meta">@Override</span> <span class="hljs-meta">@GET</span> <span class="hljs-meta">@Path(<span class="hljs-meta-string">"say"</span>)</span> <span class="hljs-keyword">public</span> List sayHello() { List list = new ArrayList&lt;&gt;(); list.add(<span class="hljs-string">"I am a test service"</span>); <span class="hljs-keyword">return</span> list; } } </code></pre> <p>使用gradle命令编译打包,<code>gradle clean build --daemon</code>,打包完后运行代码,服务启动后,在浏览器中访问:<a href="http://127.0.0.1" rel="nofollow noreferrer" target="_blank">http://127.0.0.1</a>:8080/test-demo/test/say,可以看到页面中的内容:<br /><span class="img-wrap"><img data-src="/img/bVvRHK?w=662&amp;h=350" src="https://static.segmentfault.com/v-5cc2cd8e/global/img/squares.svg" alt="图片描述" title="图片描述" style="cursor: pointer;"></span></p> <p>在Advance REST Client中看到是这样的:<br /><span class="img-wrap"><img data-src="/img/bVvRH0?w=2560&amp;h=1600" src="https://static.segmentfault.com/v-5cc2cd8e/global/img/squares.svg" alt="图片描述" title="图片描述" style="cursor: pointer;"></span></p> <p>下面实现一个与mybatis整合的demo。</p> <h3 id="articleHeader17">配置mybatis</h3> <p>在main/resource/META-INF/spring/下面创建mybatis.xml文件:</p> <div class="widget-codetool" style="display:none;"> <div class="widget-codetool--inner"> <span class="selectCode code-tool" data-toggle="tooltip" data-placement="top" title="" data-original-title="全选"></span> <span type="button" class="copyCode code-tool" data-toggle="tooltip" data-placement="top" data-clipboard-text="<?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> <beans ot; ></property> <property name=&quot;username&quot; value=&quot;${mysql.test.user}&quot; ></property> <property name=&quot;password&quot; value=&quot;${mysql.test.pwd}&quot; ></property> <!-- 配置初始化大小、最小、最大 --> <property name=&quot;initialSize&quot; value=&quot;1&quot; ></property> <property name=&quot;minIdle&quot; value=&quot;1&quot; ></property> <property name=&quot;maxActive&quot; value=&quot;20&quot; ></property> <!-- 配置获取连接等待超时的时间 --> <property name=&quot;maxWait&quot; value=&quot;30000&quot; ></property> <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 --> <property name=&quot;timeBetweenEvictionRunsMillis&quot; value=&quot;60000&quot; ></property> <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 --> <property name=&quot;minEvictableIdleTimeMillis&quot; value=&quot;300000&quot; ></property> <property name=&quot;testWhileIdle&quot; value=&quot;true&quot; ></property> <!-- 这里建议配置为TRUE,防止取到的连接不可用 --> <property name=&quot;testOnBorrow&quot; value=&quot;true&quot; ></property> <property name=&quot;testOnReturn&quot; value=&quot;false&quot; ></property> <!-- 打开PSCache,并且指定每个连接上PSCache的大小 --> <property name=&quot;poolPreparedStatements&quot; value=&quot;false&quot; ></property> <!-- 验证连接有效与否的SQL,不同的数据配置不同 --> <property name=&quot;validationQuery&quot; value=&quot;select 1 &quot; ></property> <property name=&quot;filters&quot; value=&quot;stat&quot; ></property> <!-- <property name=&quot;proxyFilters&quot;> <list> <ref bean=&quot;logFilter&quot; ></ref> </list> </property> --> </bean> <tx_advice id=&quot;advice&quot; transaction-manager=&quot;transactionManager_test&quot;> <tx_attributes> <tx_method name=&quot;select*&quot; read-only=&quot;true&quot;></tx_method> <tx_method name=&quot;find*&quot; read-only=&quot;true&quot;></tx_method> <tx_method name=&quot;get*&quot; read-only=&quot;true&quot;></tx_method> <tx_method name=&quot;has*&quot; read-only=&quot;true&quot;></tx_method> <tx_method name=&quot;count*&quot; read-only=&quot;true&quot;></tx_method> <tx_method name=&quot;search*&quot; read-only=&quot;true&quot;></tx_method> </tx_attributes> </tx_advice> <bean id=&quot;transactionManager_test&quot; class=&quot;org.springframework.jdbc.datasource.DataSourceTransactionManager&quot;> <property name=&quot;dataSource&quot;> <ref local=&quot;testDataSource&quot;></ref> </property> </bean> <!-- Session Factory --> <bean id=&quot;sqlSessionFactory_test&quot; class=&quot;org.mybatis.spring.SqlSessionFactoryBean&quot;> <property name=&quot;dataSource&quot; ref=&quot;testDataSource&quot;></property> <!-- <property name=&quot;configLocation&quot; value=&quot;classpath:META-INF/spring/configuration.xml&quot;></property>--> <!--<property name=&quot;mapperLocations&quot; value=&quot;classpath:mapper/*mapper.xml&quot;></property>--> </bean> <bean class=&quot;org.mybatis.spring.mapper.MapperScannerConfigurer&quot;> <property name=&quot;sqlSessionFactoryBeanName&quot; value=&quot;sqlSessionFactory_test&quot;></property> <property name=&quot;basePackage&quot; value=&quot;com.web.mapper&quot;></property> </bean> </beans>" title="" data-original-title="复制"></span> </div> </p></div> <pre class="hljs xml"><code><span class="hljs-meta">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">beans</span> <span class="hljs-attr">>"http://www.springframework.org/schema/beans"</span> <span class="hljs-attr">>"http://www.w3.org/2001/XMLSchema-instance"</span> <span class="hljs-attr">>"http://www.springframework.org/schema/tx"</span> <span class="hljs-attr">xsi:schemaLocation</span>=<span class="hljs-string">"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">tx:annotation-driven</span> <span class="hljs-attr">transaction-manager</span>=<span class="hljs-string">"txManager_test"</span>/&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"txManager_test"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"org.springframework.jdbc.datasource.DataSourceTransactionManager"</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"dataSource"</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">"testDataSource"</span>/&gt;</span> <span class="hljs-tag">&lt;/<span class="hljs-name">bean</span>&gt;</span> <span class="hljs-comment">&lt;!-- Use c3p0 as the database connection pool --&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"testDataSource"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"com.alibaba.druid.pool.DruidDataSource"</span> <span class="hljs-attr">init-method</span>=<span class="hljs-string">"init"</span> <span class="hljs-attr">destroy-method</span>=<span class="hljs-string">"close"</span> &gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"url"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"jdbc:mysql://${mysql.test.host}:${mysql.test.port}/${mysql.test.database}?characterEncoding=utf8"</span> /&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"username"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"${mysql.test.user}"</span> /&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"password"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"${mysql.test.pwd}"</span> /&gt;</span> <span class="hljs-comment">&lt;!-- 配置初始化大小、最小、最大 --&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"initialSize"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"1"</span> /&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"minIdle"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"1"</span> /&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"maxActive"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"20"</span> /&gt;</span> <span class="hljs-comment">&lt;!-- 配置获取连接等待超时的时间 --&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"maxWait"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"30000"</span> /&gt;</span> <span class="hljs-comment">&lt;!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 --&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"timeBetweenEvictionRunsMillis"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"60000"</span> /&gt;</span> <span class="hljs-comment">&lt;!-- 配置一个连接在池中最小生存的时间,单位是毫秒 --&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"minEvictableIdleTimeMillis"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"300000"</span> /&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"testWhileIdle"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"true"</span> /&gt;</span> <span class="hljs-comment">&lt;!-- 这里建议配置为TRUE,防止取到的连接不可用 --&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"testOnBorrow"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"true"</span> /&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"testOnReturn"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"false"</span> /&gt;</span> <span class="hljs-comment">&lt;!-- 打开PSCache,并且指定每个连接上PSCache的大小 --&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"poolPreparedStatements"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"false"</span> /&gt;</span> <span class="hljs-comment">&lt;!-- 验证连接有效与否的SQL,不同的数据配置不同 --&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"validationQuery"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"select 1 "</span> /&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"filters"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"stat"</span> /&gt;</span> <span class="hljs-comment">&lt;!-- &lt;property name="proxyFilters"&gt; &lt;list&gt; &lt;ref bean="logFilter" /&gt; &lt;/list&gt; &lt;/property&gt; --&gt;</span> <span class="hljs-tag">&lt;/<span class="hljs-name">bean</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">tx:advice</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"advice"</span> <span class="hljs-attr">transaction-manager</span>=<span class="hljs-string">"transactionManager_test"</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">tx:attributes</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">tx:method</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"select*"</span> <span class="hljs-attr">read-only</span>=<span class="hljs-string">"true"</span>/&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">tx:method</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"find*"</span> <span class="hljs-attr">read-only</span>=<span class="hljs-string">"true"</span>/&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">tx:method</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"get*"</span> <span class="hljs-attr">read-only</span>=<span class="hljs-string">"true"</span>/&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">tx:method</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"has*"</span> <span class="hljs-attr">read-only</span>=<span class="hljs-string">"true"</span>/&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">tx:method</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"count*"</span> <span class="hljs-attr">read-only</span>=<span class="hljs-string">"true"</span>/&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">tx:method</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"search*"</span> <span class="hljs-attr">read-only</span>=<span class="hljs-string">"true"</span>/&gt;</span> <span class="hljs-tag">&lt;/<span class="hljs-name">tx:attributes</span>&gt;</span> <span class="hljs-tag">&lt;/<span class="hljs-name">tx:advice</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"transactionManager_test"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"org.springframework.jdbc.datasource.DataSourceTransactionManager"</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"dataSource"</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">ref</span> <span class="hljs-attr">local</span>=<span class="hljs-string">"testDataSource"</span>/&gt;</span> <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span> <span class="hljs-tag">&lt;/<span class="hljs-name">bean</span>&gt;</span> <span class="hljs-comment">&lt;!-- Session Factory --&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"sqlSessionFactory_test"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"org.mybatis.spring.SqlSessionFactoryBean"</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"dataSource"</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">"testDataSource"</span>/&gt;</span> <span class="hljs-comment">&lt;!-- &lt;property name="configLocation" value="classpath:META-INF/spring/configuration.xml"/&gt;--&gt;</span> <span class="hljs-comment">&lt;!--&lt;property name="mapperLocations" value="classpath:mapper/*mapper.xml"/&gt;--&gt;</span> <span class="hljs-tag">&lt;/<span class="hljs-name">bean</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"org.mybatis.spring.mapper.MapperScannerConfigurer"</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"sqlSessionFactoryBeanName"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"sqlSessionFactory_test"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"basePackage"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"com.web.mapper"</span>/&gt;</span> <span class="hljs-tag">&lt;/<span class="hljs-name">bean</span>&gt;</span> <span class="hljs-tag">&lt;/<span class="hljs-name">beans</span>&gt;</span></code></pre> <p>需要注意的是数据库的配置,我们把这些以变量的形式配置,在前面所得config.properties文件中,增加mysql配置的key-value键值对,内容如下:</p> <div class="widget-codetool" style="display:none;"> <div class="widget-codetool--inner"> <span class="selectCode code-tool" data-toggle="tooltip" data-placement="top" title="" data-original-title="全选"></span> <span type="button" class="copyCode code-tool" data-toggle="tooltip" data-placement="top" data-clipboard-text="mysql.test.host=127.0.0.1 mysql.test.port=3306 mysql.test.database=dubbox_test #替换成你的数据库 mysql.test.user=root #替换成你的用户名 mysql.test.pwd=root #替换成你的密码 " title="" data-original-title="复制"></span> </div> </p></div> <pre class="hljs cmake"><code>mysql.<span class="hljs-keyword">test</span>.host=<span class="hljs-number">127.0</span>.<span class="hljs-number">0.1</span> mysql.<span class="hljs-keyword">test</span>.port=<span class="hljs-number">3306</span> mysql.<span class="hljs-keyword">test</span>.database=dubbox_test #替换成你的数据库 mysql.<span class="hljs-keyword">test</span>.user=root <span class="hljs-comment">#替换成你的用户名</span> mysql.<span class="hljs-keyword">test</span>.pwd=root <span class="hljs-comment">#替换成你的密码</span> </code></pre> <blockquote> <p>mybatis.xml中的最后一行配置<code>org.mybatis.spring.mapper.MapperScannerConfigurer</code>的属性name值为basePackage,其value值是我们项目中mapper的包路径。</p> </blockquote> <p>还有,对事物管理的配置重复了,如果你看着不舒服,可以把上面的重复部分去掉。</p> <h3 id="articleHeader18">数据库创建</h3> <p>创建一个名为dubbox_test的数据库。</p> <div class="widget-codetool" style="display:none;"> <div class="widget-codetool--inner"> <span class="selectCode code-tool" data-toggle="tooltip" data-placement="top" title="" data-original-title="全选"></span> <span type="button" class="copyCode code-tool" data-toggle="tooltip" data-placement="top" data-clipboard-text="CREATE DATABASE IF NOT EXISTS dubbox_test DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;" title="" data-original-title="复制"></span> </div> </p></div> <pre class="hljs sql"><code style="word-break: break-word; white-space: initial;"><span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">DATABASE</span> <span class="hljs-keyword">IF</span> <span class="hljs-keyword">NOT</span> <span class="hljs-keyword">EXISTS</span> dubbox_test <span class="hljs-keyword">DEFAULT</span> <span class="hljs-built_in">CHARACTER</span> <span class="hljs-keyword">SET</span> utf8 <span class="hljs-keyword">COLLATE</span> utf8_general_ci;</code></pre> <p>然后在改数据库下面创建表:</p> <div class="widget-codetool" style="display:none;"> <div class="widget-codetool--inner"> <span class="selectCode code-tool" data-toggle="tooltip" data-placement="top" title="" data-original-title="全选"></span> <span type="button" class="copyCode code-tool" data-toggle="tooltip" data-placement="top" data-clipboard-text="use dubbox_test; CREATE TABLE IF NOT EXISTS`student` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(11) DEFAULT NULL, `age` int(11) DEFAULT NULL, `sex` char(2) DEFAULT NULL, `tel` char(11) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;" title="" data-original-title="复制"></span> </div> </p></div> <pre class="hljs sql"><code><span class="hljs-keyword">use</span> dubbox_test; <span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">TABLE</span> <span class="hljs-keyword">IF</span> <span class="hljs-keyword">NOT</span> <span class="hljs-keyword">EXISTS</span><span class="hljs-string">`student`</span> ( <span class="hljs-string">`id`</span> <span class="hljs-built_in">int</span>(<span class="hljs-number">11</span>) <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> AUTO_INCREMENT, <span class="hljs-string">`name`</span> <span class="hljs-built_in">varchar</span>(<span class="hljs-number">11</span>) <span class="hljs-keyword">DEFAULT</span> <span class="hljs-literal">NULL</span>, <span class="hljs-string">`age`</span> <span class="hljs-built_in">int</span>(<span class="hljs-number">11</span>) <span class="hljs-keyword">DEFAULT</span> <span class="hljs-literal">NULL</span>, <span class="hljs-string">`sex`</span> <span class="hljs-built_in">char</span>(<span class="hljs-number">2</span>) <span class="hljs-keyword">DEFAULT</span> <span class="hljs-literal">NULL</span>, <span class="hljs-string">`tel`</span> <span class="hljs-built_in">char</span>(<span class="hljs-number">11</span>) <span class="hljs-keyword">DEFAULT</span> <span class="hljs-literal">NULL</span>, PRIMARY <span class="hljs-keyword">KEY</span> (<span class="hljs-string">`id`</span>) ) <span class="hljs-keyword">ENGINE</span>=<span class="hljs-keyword">InnoDB</span> <span class="hljs-keyword">DEFAULT</span> <span class="hljs-keyword">CHARSET</span>=utf8;</code></pre> <p>插入test数据(数据来源伪造,明星年龄我真没时间去查):</p> <div class="widget-codetool" style="display:none;"> <div class="widget-codetool--inner"> <span class="selectCode code-tool" data-toggle="tooltip" data-placement="top" title="" data-original-title="全选"></span> <span type="button" class="copyCode code-tool" data-toggle="tooltip" data-placement="top" data-clipboard-text="INSERT INTO `student`(`name`,`age`,`sex`,`tel`) VALUES ('姚明','45','男','17092679981'), ('易建联','36','男','17092679982'), ('李娜','38','女','17092679983'), ('迈克尔乔丹','46','男','17092679984'), ('刘翔','40','男','17092679985'), ('李冰冰','32','女','17092679986');" title="" data-original-title="复制"></span> </div> </p></div> <pre class="hljs sql"><code><span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> <span class="hljs-string">`student`</span>(<span class="hljs-string">`name`</span>,<span class="hljs-string">`age`</span>,<span class="hljs-string">`sex`</span>,<span class="hljs-string">`tel`</span>) <span class="hljs-keyword">VALUES</span> (<span class="hljs-string">'姚明'</span>,<span class="hljs-string">'45'</span>,<span class="hljs-string">'男'</span>,<span class="hljs-string">'17092679981'</span>), (<span class="hljs-string">'易建联'</span>,<span class="hljs-string">'36'</span>,<span class="hljs-string">'男'</span>,<span class="hljs-string">'17092679982'</span>), (<span class="hljs-string">'李娜'</span>,<span class="hljs-string">'38'</span>,<span class="hljs-string">'女'</span>,<span class="hljs-string">'17092679983'</span>), (<span class="hljs-string">'迈克尔乔丹'</span>,<span class="hljs-string">'46'</span>,<span class="hljs-string">'男'</span>,<span class="hljs-string">'17092679984'</span>), (<span class="hljs-string">'刘翔'</span>,<span class="hljs-string">'40'</span>,<span class="hljs-string">'男'</span>,<span class="hljs-string">'17092679985'</span>), (<span class="hljs-string">'李冰冰'</span>,<span class="hljs-string">'32'</span>,<span class="hljs-string">'女'</span>,<span class="hljs-string">'17092679986'</span>);</code></pre> <p><strong><em>说明:下面所有java代码的命名均与类的名字保持一致,所在位置与包名一致,故而不在写类或接口的名字。</em></strong></p> <h3 id="articleHeader19">接口定义(interface)</h3> <div class="widget-codetool" style="display:none;"> <div class="widget-codetool--inner"> <span class="selectCode code-tool" data-toggle="tooltip" data-placement="top" title="" data-original-title="全选"></span> <span type="button" class="copyCode code-tool" data-toggle="tooltip" data-placement="top" data-clipboard-text="package com.web.service; import com.web.pojos.Student; import java.util.List; /** * 查询学生信息 */ public interface StudentService { List<Student> getStudentsInfo(int sid); } " title="" data-original-title="复制"></span> </div> </p></div> <pre class="hljs java"><code><span class="hljs-keyword">package</span> com.web.service; <span class="hljs-keyword">import</span> com.web.pojos.Student; <span class="hljs-keyword">import</span> java.util.List; <span class="hljs-comment">/** * 查询学生信息 */</span> <span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">interface</span> <span class="hljs-title">StudentService</span> </span>{ <span class="hljs-function">List&lt;Student&gt; <span class="hljs-title">getStudentsInfo</span><span class="hljs-params">(<span class="hljs-keyword">int</span> sid)</span></span>; } </code></pre> <h3 id="articleHeader20">实现接口(implements)</h3> <div class="widget-codetool" style="display:none;"> <div class="widget-codetool--inner"> <span class="selectCode code-tool" data-toggle="tooltip" data-placement="top" title="" data-original-title="全选"></span> <span type="button" class="copyCode code-tool" data-toggle="tooltip" data-placement="top" data-clipboard-text="package com.web.biz; import com.alibaba.dubbo.rpc.protocol.rest.support.ContentType; import com.web.Repository.StudentRepo; import com.web.pojos.Student; import com.web.service.StudentService; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.stereotype.Component; import javax.annotation.Resource; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import java.util.List; @Component(&quot;studentService&quot;) @Path(&quot;student&quot;) @Produces({ContentType.APPLICATION_JSON_UTF_8}) public class StudentServiceImpl implements StudentService { Log logger = LogFactory.getLog(StudentServiceImpl.class); @Resource private StudentRepo studentRepo; /** * 获取学生信息 * @param id * @return */ @Override @GET @Path(&quot;getinfo/{id: \d+}&quot;) public List<Student> getStudentsInfo(@PathParam(&quot;id&quot;) int id) { logger.debug(&quot;获取学生信息,学号为:&quot; + id); System.out.println(&quot;获取学生信息,学号为:&quot; + id); return studentRepo.getStudentInfo(id); } } " title="" data-original-title="复制"></span> </div> </p></div> <pre class="hljs kotlin"><code><span class="hljs-keyword">package</span> com.web.biz; <span class="hljs-keyword">import</span> com.alibaba.dubbo.rpc.protocol.rest.support.ContentType; <span class="hljs-keyword">import</span> com.web.Repository.StudentRepo; <span class="hljs-keyword">import</span> com.web.pojos.Student; <span class="hljs-keyword">import</span> com.web.service.StudentService; <span class="hljs-keyword">import</span> org.apache.commons.logging.Log; <span class="hljs-keyword">import</span> org.apache.commons.logging.LogFactory; <span class="hljs-keyword">import</span> org.springframework.stereotype.Component; <span class="hljs-keyword">import</span> javax.<span class="hljs-keyword">annotation</span>.Resource; <span class="hljs-keyword">import</span> javax.ws.rs.GET; <span class="hljs-keyword">import</span> javax.ws.rs.Path; <span class="hljs-keyword">import</span> javax.ws.rs.PathParam; <span class="hljs-keyword">import</span> javax.ws.rs.Produces; <span class="hljs-keyword">import</span> java.util.List; <span class="hljs-meta">@Component(<span class="hljs-meta-string">"studentService"</span>)</span> <span class="hljs-meta">@Path(<span class="hljs-meta-string">"student"</span>)</span> <span class="hljs-meta">@Produces({ContentType.APPLICATION_JSON_UTF_8})</span> <span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">StudentServiceImpl</span> <span class="hljs-title">implements</span> <span class="hljs-title">StudentService</span> </span>{ Log logger = LogFactory.getLog(StudentServiceImpl.<span class="hljs-keyword">class</span>); <span class="hljs-meta">@Resource</span> <span class="hljs-keyword">private</span> StudentRepo studentRepo; <span class="hljs-comment">/** * 获取学生信息 * <span class="hljs-doctag">@param</span> id * <span class="hljs-doctag">@return</span> */</span> <span class="hljs-meta">@Override</span> <span class="hljs-meta">@GET</span> <span class="hljs-meta">@Path(<span class="hljs-meta-string">"getinfo/{id: \d+}"</span>)</span> <span class="hljs-keyword">public</span> List&lt;Student&gt; getStudentsInfo(<span class="hljs-meta">@PathParam(<span class="hljs-meta-string">"id"</span>)</span> int id) { logger.debug(<span class="hljs-string">"获取学生信息,学号为:"</span> + id); System.<span class="hljs-keyword">out</span>.println(<span class="hljs-string">"获取学生信息,学号为:"</span> + id); <span class="hljs-keyword">return</span> studentRepo.getStudentInfo(id); } } </code></pre> <h3 id="articleHeader21">业务逻辑(repository)</h3> <div class="widget-codetool" style="display:none;"> <div class="widget-codetool--inner"> <span class="selectCode code-tool" data-toggle="tooltip" data-placement="top" title="" data-original-title="全选"></span> <span type="button" class="copyCode code-tool" data-toggle="tooltip" data-placement="top" data-clipboard-text="package com.web.Repository; import com.web.mapper.StudentInfoMapper; import com.web.pojos.Student; import org.springframework.stereotype.Repository; import javax.annotation.Resource; import java.util.List; @Repository(&quot;studentRepo&quot;) public class StudentRepo { @Resource private StudentInfoMapper studentInfoMapper; public List<Student> getStudentInfo(final int sid) { if (sid == 0) { return null; } return studentInfoMapper.getStudentInfo(sid); } } " title="" data-original-title="复制"></span> </div> </p></div> <pre class="hljs kotlin"><code><span class="hljs-keyword">package</span> com.web.Repository; <span class="hljs-keyword">import</span> com.web.mapper.StudentInfoMapper; <span class="hljs-keyword">import</span> com.web.pojos.Student; <span class="hljs-keyword">import</span> org.springframework.stereotype.Repository; <span class="hljs-keyword">import</span> javax.<span class="hljs-keyword">annotation</span>.Resource; <span class="hljs-keyword">import</span> java.util.List; <span class="hljs-meta">@Repository(<span class="hljs-meta-string">"studentRepo"</span>)</span> <span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">StudentRepo</span> </span>{ <span class="hljs-meta">@Resource</span> <span class="hljs-keyword">private</span> StudentInfoMapper studentInfoMapper; <span class="hljs-keyword">public</span> List&lt;Student&gt; getStudentInfo(<span class="hljs-keyword">final</span> int sid) { <span class="hljs-keyword">if</span> (sid == <span class="hljs-number">0</span>) { <span class="hljs-keyword">return</span> <span class="hljs-literal">null</span>; } <span class="hljs-keyword">return</span> studentInfoMapper.getStudentInfo(sid); } } </code></pre> <h3 id="articleHeader22">dao层(mapper)</h3> <div class="widget-codetool" style="display:none;"> <div class="widget-codetool--inner"> <span class="selectCode code-tool" data-toggle="tooltip" data-placement="top" title="" data-original-title="全选"></span> <span type="button" class="copyCode code-tool" data-toggle="tooltip" data-placement="top" data-clipboard-text="package com.web.mapper; import com.web.pojos.Student; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Result; import org.apache.ibatis.annotations.Results; import org.apache.ibatis.annotations.Select; import org.springframework.stereotype.Component; import java.util.List; @Component(&quot;studentInfoMapper&quot;) public interface StudentInfoMapper { @Select( &quot;<script>select * from student where 1 = 1 &quot; + &quot; <if test=&quot;id != null or id != 0&quot;> and id = #{id}</if>&quot; + &quot; limit 1000</script>&quot;) @Results({ @Result(id = true, property = &quot;id&quot;, column = &quot;id&quot;), @Result(property = &quot;name&quot;, column = &quot;name&quot;), @Result(property = &quot;age&quot;, column = &quot;age&quot;), @Result(property = &quot;sex&quot;, column = &quot;sex&quot;), @Result(property = &quot;tel&quot;, column = &quot;tel&quot;) }) List<Student> getStudentInfo(@Param(&quot;id&quot;) final int id); } " title="" data-original-title="复制"></span> </div> </p></div> <pre class="hljs css"><code><span class="hljs-selector-tag">package</span> <span class="hljs-selector-tag">com</span><span class="hljs-selector-class">.web</span><span class="hljs-selector-class">.mapper</span>; <span class="hljs-selector-tag">import</span> <span class="hljs-selector-tag">com</span><span class="hljs-selector-class">.web</span><span class="hljs-selector-class">.pojos</span><span class="hljs-selector-class">.Student</span>; <span class="hljs-selector-tag">import</span> <span class="hljs-selector-tag">org</span><span class="hljs-selector-class">.apache</span><span class="hljs-selector-class">.ibatis</span><span class="hljs-selector-class">.annotations</span><span class="hljs-selector-class">.Param</span>; <span class="hljs-selector-tag">import</span> <span class="hljs-selector-tag">org</span><span class="hljs-selector-class">.apache</span><span class="hljs-selector-class">.ibatis</span><span class="hljs-selector-class">.annotations</span><span class="hljs-selector-class">.Result</span>; <span class="hljs-selector-tag">import</span> <span class="hljs-selector-tag">org</span><span class="hljs-selector-class">.apache</span><span class="hljs-selector-class">.ibatis</span><span class="hljs-selector-class">.annotations</span><span class="hljs-selector-class">.Results</span>; <span class="hljs-selector-tag">import</span> <span class="hljs-selector-tag">org</span><span class="hljs-selector-class">.apache</span><span class="hljs-selector-class">.ibatis</span><span class="hljs-selector-class">.annotations</span><span class="hljs-selector-class">.Select</span>; <span class="hljs-selector-tag">import</span> <span class="hljs-selector-tag">org</span><span class="hljs-selector-class">.springframework</span><span class="hljs-selector-class">.stereotype</span><span class="hljs-selector-class">.Component</span>; <span class="hljs-selector-tag">import</span> <span class="hljs-selector-tag">java</span><span class="hljs-selector-class">.util</span><span class="hljs-selector-class">.List</span>; @<span class="hljs-keyword">Component</span>("<span class="hljs-keyword">studentInfoMapper</span>") public interface StudentInfoMapper { @<span class="hljs-keyword">Select</span>( <span class="hljs-string">"&lt;script&gt;select * from student where 1 = 1 "</span> + <span class="hljs-string">" &lt;if test="id != null or id != 0""&gt; and id = #{id}&lt;/if&gt;""</span> +</code></p>
脚本宝典为你提供优质服务
脚本宝典 » dubbox/dubbo+spring+mybatis+gradle构建REST服务

发表评论

提供最优质的资源集合

立即查看 了解详情