- 首页 > 生活 > >
Dubbo 03: 直连式 + 接口工程( 二 )
dubbo的服务提供者的配置文件
<?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:dubbo="http://dubbo.apache.org/schema/dubbo"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd"><!-- 服务提供者标识 --><dubbo:application name="o4-link-userservice-provider"/><!-- 使用的协议和端口 --><dubbo:protocol name="dubbo" port="20880"/><!-- 提供的服务 --><dubbo:service interface="com.example.dubbo.service.UserService"ref="userService" registry="N/A"/><!-- 服务的实现类--><bean id="userService" class="com.example.dubbo.service.impl.userServiceImpl"/></beans>
web.xml
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"version="4.0"><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:dubbo-link-userservice-provider.xml</param-value></context-param><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener></web-app>
提供的服务实现
package com.example.dubbo.service.impl;import com.example.dubbo.model.User;import com.example.dubbo.service.UserService;public class userServiceImpl implements UserService {@Overridepublic User queryUserById(String id) {User user = new User();user.setId(id);user.setName("橘子");user.setAge("18");return user;}@Overridepublic int queryAllUserCount() {return 3;}}
工程3
- 结构
文章插图
- pom文件:要引入接口工程的依赖,知道可以申请哪些服务
<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 http://maven.apache.org/maven-v4_0_0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.example.dubbo</groupId><artifactId>o5-link-consumer</artifactId><packaging>war</packaging><version>1.0.0</version><dependencies><!--Spring依赖--><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>4.3.16.RELEASE</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>4.3.16.RELEASE</version></dependency><!--dubbo依赖--><dependency><groupId>com.alibaba</groupId><artifactId>dubbo</artifactId><version>2.6.2</version></dependency><!-- 接口工程 --><dependency><groupId>com.example.dubbo</groupId><artifactId>o3-link-interface</artifactId><version>1.0.0</version></dependency></dependencies><build><plugins><!--JDK1.8编译插件--><plugin><artifactId>maven-compiler-plugin</artifactId><version>3.1</version><configuration><source>1.8</source><target>1.8</target></configuration></plugin></plugins></build></project>
- dubbo里消费者的配置文件
<?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:dubbo="http://dubbo.apache.org/schema/dubbo"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd"><!-- 消费者标识 --><dubbo:application name="o5-link-consumer"/><!-- 引用的远程服务 --><dubbo:reference id="userService" interface="com.example.dubbo.service.UserService" url="dubbo://127.0.0.1:20880" registry="N/A"/></beans>
经验总结扩展阅读
-
-
-
-
-
-
2022年10月26日粉刷墙壁黄道吉日 2022年10月26日粉刷墙壁行吗
-
|西安地铁保安拖拽女乘客,处理结果公布:为什么我们依旧愤怒?
-
-
过滤水壶是过滤开水还是自来水,滤水壶可以直接过滤开水吗?
-
-
-
-
-
-
-
本文转自:大庆晚报你有没有尝试过 情感实录∣纵然故事再多,也无法拼凑出完整的他
-
-
-
-
为什么会长皮脂腺囊肿,耳垂有硬块正常吗?耳垂为什么会长硬疙瘩?