1.属性文件 init.properties
##[dubbo安装在哪台机器上,必需指向到哪台机器,与提供者注册的机器一致]##
##[dubbo服务注册地址:服务器上]##
#dubbo.registry.address=119.29.179.201:2181
dubbo.registry.application=ecommerce-web
##[dubbo服务注册地址:开发本地机器]##
dubbo.registry.address=127.0.0.1:2181
##[dubbo服务缓存文件位置]##
dubbo.catalina.home=dubbo缓存文件位置
dubbo.catalina.home.win=C:/ecom/dubbo-registry-catalina/ecommerce-web/dubbo-registry.properties
dubbo.catalina.home.linux=/home/ecom/dubbo-registry-catalina/ecommerce-web/dubbo-registry.properties
##[log日志文件位置]##
log.dir=log日志文件位置
log.dir.win=C:/ecom/log/ecommerce-web/web.log
log.dir.linux=/home/ecom/log/ecommerce-web/web.log
## 需要改变的地址,打包的时候,以下二选一 ##
## 打包到win系统 ##
dubbo.registry.address.file=C:/ecom/dubbo-registry-catalina/ecommerce-web/dubbo-registry.properties
log.home.dir=C:/ecom/log/ecommerce-web/web.log
## 打包到linux系统 ##
#dubbo.registry.address.file=/home/ecom/dubbo-registry-catalina/ecommerce-web/dubbo-registry.properties
#log.home.dir=/home/ecom/log/ecommerce-web/web.log
2.配置文件 spring-mvc.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<mvc:annotation-driven />
<context:property-placeholder location="classpath:../properties/init.properties"/>
<!-- 启用spring mvc 注解 -->
<context:annotation-config />
<!-- 消费方应用名,用于计算依赖关系,不是匹配条件,不要与提供方一样 -->
<dubbo:application name="${dubbo.registry.application}" />
<!-- 使用zookeeper注册中心暴露服务地址 -->
<!--打包注意环境: linux操作系统 -->
<!-- <dubbo:registry protocol="zookeeper" address="127.0.0.1:2181" file="/home/ecom/dubbo-registry-catalina/ecommerce-web/dubbo-registry.properties"/> -->
<!--打包注意环境: win操作系统 -->
<!-- <dubbo:registry protocol="zookeeper" address="127.0.0.1:2181" file="C:/ecom/dubbo-registry-catalina/ecommerce-web/dubbo-registry.properties"/> -->
<dubbo:registry protocol="zookeeper" address="${dubbo.registry.address}" file="${dubbo.registry.address.file}"/>
<!-- 生成远程服务代理,可以像使用本地bean一样使用demoService -->
<!-- 样例服务,begin -->
<!-- dubbo:reference 增加属性check="false"表示,启动的时候不检查提供者是否已经启动 -->
<dubbo:reference id="interface_demoService" interface="com.ecommerce.platform.demo.server.IDemoService" check="false" generic="false"/>
<!-- 样例服务,end -->
<!-- 接口服务 -->
<dubbo:reference id="interface_interfaceService" interface="com.ecommerce.platform.server.IInterfaceService" check="false" generic="false"/>
<dubbo:reference id="interface_orghierService" interface="com.ecommerce.platform.server.IOrghierService" check="false" generic="false"/>
<dubbo:reference id="interface_goodsCategoryService" interface="com.ecommerce.platform.server.IGoodsCategoryService" check="false" generic="false"/>
<dubbo:reference id="interface_goodsService" interface="com.ecommerce.platform.server.IGoodsService" check="false" generic="false"/>
<dubbo:reference id="interface_authLogService" interface="com.ecommerce.platform.server.IAuthLogService" check="false" generic="false"/>
<dubbo:reference id="interface_membersService" interface="com.ecommerce.platform.server.IMembersService" check="false" generic="false"/>
<dubbo:reference id="interface_mktGoodsRelationService" interface="com.ecommerce.platform.server.IMktGoodsRelationService" check="false" generic="false"/>
<dubbo:reference id="interface_sysDataService" interface="com.ecommerce.platform.server.ISysDataService" check="false" generic="false"/>
<dubbo:reference id="interface_brandService" interface="com.ecommerce.platform.server.IBrandService" check="false" generic="false"/>
<dubbo:reference id="interface_orderService" interface="com.ecommerce.platform.server.IOrderService" check="false" generic="false"/>
<dubbo:reference id="interface_huiGoService" interface="com.ecommerce.platform.server.IHuiGoService" check="false" generic="false"/>
<dubbo:reference id="interface_commonService" interface="com.ecommerce.platform.server.ICommonService" check="false" generic="false"/>
<!-- 计划任务 -->
<dubbo:reference id="plnadapter_plnAdapterLogService" interface="com.ecommerce.platform.plnadapter.service.IPlnAdapterLogService" check="false" generic="false"/>
<dubbo:reference id="plnadapter_plnAdapterTaskService" interface="com.ecommerce.platform.plnadapter.service.IPlnAdapterTaskService" check="false" generic="false"/>
<dubbo:reference id="plnadapter_plnAdapterTaskConfigService" interface="com.ecommerce.platform.plnadapter.service.IPlnAdapterTaskConfigService" check="false" generic="false"/>
<dubbo:reference id="plnadapter_procedureService" interface="com.ecommerce.platform.plnadapter.procedure.server.IProcedureService" check="false" generic="false"/>
<!-- 上面的是ok的 -->
<!-- 设置使用注解的类所在的包 -->
<!-- 扫包1 -->
<context:component-scan base-package="com.ecommerce.platform.web.controller" />
<!-- 扫包2 -->
<context:component-scan base-package="com.ecommerce.platform.demo.web.controller"/>
<!-- 扫包3 -->
<context:component-scan base-package="com.ecommerce.platform.web.test" />
<!-- 对模型视图名称的解析,即在模型视图名称添加前后缀 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/pages/" />
<property name="suffix" value=".jsp" />
</bean>
<!-- 避免IE在ajax请求时,返回json出现下载 -->
<bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>application/json;charset=UTF-8</value>
</list>
</property>
</bean>
<!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 -->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<ref bean="mappingJacksonHttpMessageConverter" />
</list>
</property>
</bean>
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- 设置上传文件的最大尺寸为5MB -->
<property name="maxUploadSize">
<value>5242880</value>
</property>
</bean>
<!-- SpringMVC在超出上传文件限制时,会抛出org.springframework.web.multipart.MaxUploadSizeExceededException -->
<!-- 该异常是SpringMVC在检查上传的文件信息时抛出来的,而且此时还没有进入到Controller方法中 -->
<bean id="exceptionResolver"
class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="exceptionMappings">
<props>
<!-- 遇到MaxUploadSizeExceededException异常时,自动跳转到/WEB-INF/jsp/error_fileupload.jsp页面 -->
<prop key="org.springframework.web.multipart.MaxUploadSizeExceededException">error_fileupload</prop>
</props>
</property>
</bean>
</beans>