dubbo

web.xml

监听spring配置文件

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://java.sun.com/xml/ns/javaee"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	version="2.5">
	
	<!--作为服务的配置-->
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>

	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:dubbo.xml</param-value>
	</context-param>
	
	<!--作为controler入口的配置-->
	<servlet>
        <servlet-name>springmvc</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:dubbo.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    
    <servlet-mapping>
        <servlet-name>springmvc</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
    
</web-app>

dubbo.xml

<?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://code.alibabatech.com/schema/dubbo"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
       
    <context:property-placeholder location="classpath:dubbo.properties" />
    <dubbo:application name="provider"/><!--服务名称-->
    <dubbo:registry address="zookeeper://192.168.58.167:2181"/><!--配置注册中心地址--> 
    <dubbo:protocol name="dubbo" port="${port}"/><!--注册中心提供者,不提供服务只消费不用配,集群也要端口不同 name: 请求协议 port:提供者的请求端口,不能重复 -->
    <dubbo:annotation package="包"/><!--包扫描,@Service作为提供者,@Controller作为消费者-->
    
</beans>

Service

一定要有接口,可以单独作为一个模块

public interface Service {
	Object funtion(Object object);
}

实现类要加上@Service注解

@Service(timeout = )//debug时设置
public class ServiceImpl implements Service {
 @Override
    public Object funtion(Object object) {
		return null;
	}

传递的实体类要实现Serializable接口

Controller

模块要引用服务接口模块

@Controller
public class Controller {
	//用Reference引用服务接口,测试时可以check=false不测试服务
    @Reference(check = true, loadbalance = "random/roundrobin/leastactive")
    private Service service;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值