SpringMVC + Dubbo配置
阿新 • • 發佈:2018-11-12
SpringMVC 與 Dubbo 的配置 1.applicationContext.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xmlns="http://www.springframework.org/schema/beans" 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"> <!-- consumer application name --> <dubbo:application name="order-web" owner="order" organization="xxx" /> <!-- registry address, used for consumer to discover services--> <dubbo:registry address="zookeeper://192.168.1.168:2181"/> <!-- 掃描註解包路徑,多個包用逗號分隔,不填pacakge表示掃描當前ApplicationContext中所有的類 --> <dubbo:annotation package="com.xxx" /> <dubbo:reference id="dictionaryService" interface="com.xxx.api.service.dictionary.DictionaryService"/> </beans> 2.spring-mvc.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:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" 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://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd"> <context:property-placeholder location="classpath:*.properties"/> <dubbo:annotation package="com.xxx" /> <mvc:annotation-driven conversion-service="conversionService"/> <!-- 避免IE執行AJAX時,返回JSON出現下載檔案 --> <bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>text/html;charset=UTF-8</value> </list> </property> </bean> <bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean"> <property name="converters"> <set> <!--<bean class="com.xxx.standard.converters.StringToBooleanConverterFactory"/>--> <bean class="org.springframework.core.convert.support.StringToBooleanConverter"></bean> </set> </property> <property name="formatters"> <set> <bean class="com.xxx.parent.converters.DateFormatter"></bean> </set> </property> </bean> <!-- 對模型檢視名稱的解析,即在模型檢視名稱新增前後綴 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> <property name="prefix" value="/WEB-INF/views/" /> <property name="suffix" value=".jsp" /> </bean> <!-- 配置檢視 BeanNameViewResolver 解析器: 使用檢視的名字來解析檢視 --> <!-- 通過 order 屬性來定義檢視解析器的優先順序, order 值越小優先順序越高 --> <bean class="org.springframework.web.servlet.view.BeanNameViewResolver"> <property name="order" value="100"></property> </bean> <!--配置攔截器, 多個攔截器,順序執行 --> <mvc:interceptors> <!--所有需要登入的頁面--> <mvc:interceptor> <mvc:mapping path="/**"/> <bean class="com.xxx.account.analyze.intercepter.LoginInterceptor"></bean> </mvc:interceptor> <!-- 處理全域性資訊 --> <mvc:interceptor> <mvc:mapping path="/**" /> <bean class="com.xxx.parent.intercepter.BaseInterceptor"></bean> </mvc:interceptor> <!-- 當設定多個攔截器時,先按順序呼叫preHandle方法,然後逆序呼叫每個攔截器的postHandle和afterCompletion方法 --> </mvc:interceptors> </beans>