A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

本帖最后由 谷粒姐姐 于 2018-7-25 11:21 编辑

3.2 配置离线约束
地址:
3.3 入门小 Demo
3.3.1 服务提供者开发
开发步骤:
1)创建 Maven工程(WARdubboxdemo-service,在 pom.xml中引入依赖
[AppleScript] 纯文本查看 复制代码
<project  xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 [url=http://maven.apache.org/xsd/maven-4.0.0.xsd]http://maven.apache.org/xsd/maven-4.0.0.xsd[/url]">

<modelVersion>4.0.0</modelVersion>

<groupId>cn.itcast.dubboxdemo</groupId>

<artifactId>dubboxdemo-service</artifactId>

<version>0.0.1-SNAPSHOT</version>

<packaging>war</packaging>

<properties>

<spring.version>4.2.4.RELEASE</spring.version>

</properties>

<dependencies>

<!--  Spring  -->

<dependency>

<groupId>org.springframework</groupId>
[AppleScript] 纯文本查看 复制代码
<artifactId>spring-context</artifactId>


<version>${spring.version}</version>


</dependency>


<dependency>


<groupId>org.springframework</groupId>


<artifactId>spring-beans</artifactId>


<version>${spring.version}</version>


</dependency>


<dependency>


<groupId>org.springframework</groupId>


<artifactId>spring-webmvc</artifactId>

<version>${spring.version}</version>


</dependency>


<dependency>


<groupId>org.springframework</groupId>


<artifactId>spring-jdbc</artifactId>

<version>${spring.version}</version>


</dependency>


<dependency>


<groupId>org.springframework</groupId>


<artifactId>spring-aspects</artifactId>


<version>${spring.version}</version>


</dependency>
[AppleScript] 纯文本查看 复制代码
<dependency>


<groupId>org.springframework</groupId>


<artifactId>spring-jms</artifactId>

<version>${spring.version}</version>


</dependency>


<dependency>


<groupId>org.springframework</groupId>


<artifactId>spring-context-support</artifactId>


<version>${spring.version}</version>


</dependency>

<!-- dubbo 相 关 -->

<dependency>


<groupId>com.alibaba</groupId>


<artifactId>dubbo</artifactId>

<version>2.8.4</version>


</dependency>


<dependency>


<groupId>org.apache.zookeeper</groupId>


<artifactId>zookeeper</artifactId>

<version>3.4.6</version>


</dependency>


<dependency>


<groupId>com.github.sgroschupf</groupId>
[AppleScript] 纯文本查看 复制代码
<artifactId>zkclient</artifactId>

<version>0.1</version>


</dependency>


<dependency>


<groupId>javassist</groupId>

<artifactId>javassist</artifactId>

<version>3.11.0.GA</version>


</dependency>


</dependencies>


<build>


<plugins>


<plugin>


<groupId>org.apache.maven.plugins</groupId>


<artifactId>maven-compiler-plugin</artifactId>

<version>2.3.2</version>


<configuration>


<source>1.7</source>


<target>1.7</target>


</configuration>


</plugin>


<plugin>


<groupId>org.apache.tomcat.maven</groupId>


<artifactId>tomcat7-maven-plugin</artifactId>
[AppleScript] 纯文本查看 复制代码
<configuration>

<!-- 指定端口 -->

<port>8081</port>

<!-- 请求路径 -->

<path>/</path>


</configuration>


</plugin>


</plugins>


</build>


</project>
2)在工程的 webapps 下创建 WEB-INF 文件夹,创建 web.xml
return"itcast";
}
}
注意:Service 注解与原来不同,需要引入 com.alibaba 包下的
5)编写配置文件
在 src/main/resources 下创建 applicationContext-service.xml ,内容如下:
[AppleScript] 纯文本查看 复制代码
<?xml  version="1.0"  encoding="UTF-8"?>
<beans  xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xmlns:mvc="http://www.springframework.org/schema/mvc"

xsi:schemaLocation="http://www.springframework.org/schema/beans [url=http://www.springframework.org/schema/beans/spring-beans.xsd]http://www.springframework.org/schema/beans/spring-beans.xsd[/url]

[url=http://www.springframework.org/schema/mvc]http://www.springframework.org/schema/mvc[/url] [url=http://www.springframework.org/schema/mvc/spring-mvc.xsd]http://www.springframework.org/schema/mvc/spring-mvc.xsd[/url]

[url=http://code.alibabatech.com/schema/dubbo]http://code.alibabatech.com/schema/dubbo[/url] [url=http://code.alibabatech.com/schema/dubbo/dubbo.xsd]http://code.alibabatech.com/schema/dubbo/dubbo.xsd[/url]

[url=http://www.springframework.org/schema/context]http://www.springframework.org/schema/context[/url] [url=http://www.springframework.org/schema/context/spring-context.xsd]http://www.springframework.org/schema/context/spring-context.xsd[/url]">


<dubbo:application  name="dubboxdemo-service"/>

<dubbo:registry  address="zookeeper://192.168.25.132:2181"/>

<dubbo:annotation  package="cn.itcast.dubboxdemo.service"  />

</beans>
注意:dubbo:annotation 用于扫描@Service 注解。
6)测试运行
tomcat7:run


0 个回复

您需要登录后才可以回帖 登录 | 加入黑马