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