dubbo 学习笔记 -- provider端
来源:互联网 发布:php取对象的值 编辑:程序博客网 时间:2024/05/18 15:26
2013-06-03 15:20 1254人阅读 评论(0)收藏 举报
服务端的配置文件: provider.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"
- 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 ">
- <!-- Application name -->
- <dubbo:application name="Frame" />
- <!-- registry address, used for service to register itself -->
- <dubbo:registry address="multicast://224.5.6.7:1234" />
- <!-- expose this service through dubbo protocol, through port 20880 -->
- <dubbo:protocol name="dubbo" port="20880" />
- <!-- which service interface do we expose? -->
- <dubbo:service interface="merchant.shop.service.IHelloService" ref="helloService" />
- <!-- bean配置 -->
- <bean id="helloService"
- class="merchant.shop.service.impl.HelloServiceImpl">
- </bean>
- </beans>
此处interface的地址要与consumer端的一致,所以在服务端工程中新建了和客户端工程一样的路径来保存service
spring 配置文件 : providerApplicationContext.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"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
- <!-- spring 与 ibatis 衔接 -->
- <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
- <property name="configLocation" value="provider-sql-map-config.xml"></property>
- <property name="dataSource" ref="dataSource"/>
- </bean>
- <!-- 数据源基本配置 -->
- <bean id="dataSource"
- class="org.springframework.jndi.JndiObjectFactoryBean">
- <property name="jndiName">
- <value>java:/comp/env/test</value>
- </property>
- </bean>
- <!-- 事务配置 -->
- <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
- <property name="dataSource" ref="dataSource"></property>
- </bean>
- <!-- 声明式事务管理 -->
- <bean id="baseTransactionProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true">
- <property name="transactionManager" ref="transactionManager"></property>
- <property name="transactionAttributes">
- <props>
- <prop key="add*">PROPAGATION_REQUIRED</prop>
- <prop key="edit*">PROPAGATION_REQUIRED</prop>
- <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
- </props>
- </property>
- </bean>
- </beans>
服务端需要启动的两个文件如下 :
- package com.sitech.comm.dubbo;
- import org.springframework.context.ApplicationContext;
- import org.springframework.context.support.ClassPathXmlApplicationContext;
- public class Provider {
- public static void init() throws Exception {
- ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"provider.xml"});
- context.start();
- singleton();
- }
- public static ApplicationContext context = null;
- public static ApplicationContext singleton() {
- if (context == null) {
- context = new ClassPathXmlApplicationContext(new String[] {"providerApplicationContext.xml"});
- }
- return context;
- };
- }
- package com.sitech.comm.dubbo;
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServlet;
- import com.sitech.comm.log.LogWritter;
- public class ProviderInit extends HttpServlet {
- public void init() throws ServletException {
- try {
- System.out.println("初始化dubbo服务端");
- Provider.init();
- } catch (Exception e) {
- System.out.println("初始化dubbo服务端失败");
- }
- }
- }
web.xml 中增加启动如下 :
- <servlet>
- <servlet-name>ProviderInit</servlet-name>
- <servlet-class>
- com.sitech.comm.dubbo.ProviderInit
- </servlet-class>
- <load-on-startup>1</load-on-startup>
- </servlet>
consumer客户端就可以远程调用另一个工程的服务了
这里出问题,一般都是配置文件的问题,如数据库的连接,spring 与 ibatis 衔接 时的配置文件等
0 0
- dubbo 学习笔记 -- provider端
- dubbo 学习笔记 -- provider端
- dubbo 学习笔记 -- provider端
- dubbo 学习笔记 -- provider端
- Dubbo学习笔记(三) Provider和Consumer
- Dubbo学习笔记:No provider available for the service ...异常问题的解决
- dubbo 学习笔记 -- consumer端
- dubbo 学习笔记 -- consumer端
- dubbo 学习笔记 -- consumer端
- dubbo 学习笔记 -- consumer端
- Content Provider 学习笔记
- dubbo学习笔记
- 阿里Dubbo学习笔记
- dubbo-学习笔记
- dubbo入门学习笔记
- dubbo学习笔记
- dubbo 学习笔记
- dubbo学习笔记
- [NOIP 2014复习]第二章:搜索
- [1525]字符统计2 (哈希)SDUT
- iframe标签实现form表单提交无页面刷新(不需要js)---解析
- 在应用程序级别之外使用注册为 allowDefinition='MachineToApplication' 的节是错误的。如果在 IIS 中没有将虚拟目录配置为应用程序,则可能导致此错误。
- linux内核的数据结构:3 每CPU变量
- dubbo 学习笔记 -- provider端
- Linux文本编辑器VIM的七项实用操作技
- 赫夫曼树
- hibernate的编码
- ubuntu下mysql的常用命令
- java中重载与重写的区别
- 软件开发的周期
- 时间复杂度为O(n),空间复杂度为O(1)
- cygwin+windows 使用JNI时 .c文件打包成.so