All Downloads are FREE. Search and download functionalities are using the official Maven repository.

springmvc.spring-mvc-openApi.xml Maven / Gradle / Ivy

<?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:p="http://www.springframework.org/schema/p"
	xmlns:c="http://www.springframework.org/schema/c"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	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">

	<description>openApi的核心配置 依赖于spring-mvc-messageConverters.xml、spring-mvc-jsonp.xml
	其中包含mvc:annotation-driven 注意避免重复定义</description>
	
	<bean id="apiRequestMappingHandlerMapping" class="cn.meteor.module.core.openApi.annotation.ApiMethodHandlerMapping" lazy-init="false"><!-- 提供支持ApiMethod自定义Mapping注解 -->
		<!-- <property name="order"  value="-2" /> --><!-- 不提高排序级别,使默认RequestMapping优先,以后待优化 -->
		<property name="contentNegotiationManager" ref="contentNegotiationManager" />
		<property name="useHandler"  value="${core.openApi.apiRequestMappingHandlerMapping.useHandler:false}" /><!-- 是否通过xml的handler映射方法 -->
	</bean>
	
	<!-- 定义参数内容协商策略,扩展为可指定起始url -->
	<bean id="restParameterContentNegotiationStrategy" class="cn.meteor.module.core.openApi.accept.RestParameterContentNegotiationStrategy">
		<constructor-arg>
			<map>
            	<entry key="json" value="application/json;charset=UTF-8" />
				<entry key="xml" value="application/xml;charset=UTF-8" />
				<entry key="html" value="text/html;charset=UTF-8" />
				<entry key="enc_json" value="text/enc_json;charset=UTF-8" />
			</map>
		</constructor-arg>
		<property name="parameterName" value="${core.openApi.restParameterContentNegotiationStrategy.parameterName:format}" />
		<property name="defaultMediaTypeKey" value="${core.openApi.restParameterContentNegotiationStrategy.defaultMediaTypeKey:json}" />
		<property name="startUrl" value="${core.openApi.restParameterContentNegotiationStrategy.startUrl:/rest}" />
	</bean>
	
	<!-- 空bean,方便defaultContentTypeStrategy可配置 -->
	<bean id="nullBean"  class="cn.meteor.module.core.spring.NullFactoryBean"  lazy-init="false"></bean>
	<!-- 提供支持通过format控制json或xml响应 -->
	<!-- <bean id="contentNegotiationManager"  class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean"> -->
	<bean id="contentNegotiationManager"  class="cn.meteor.module.core.openApi.accept.RestContentNegotiationManagerFactoryBean">
		<property name="favorPathExtension" value="${core.openApi.contentNegotiationManager.favorPathExtension:false}" />
		<property name="favorParameter" value="${core.openApi.contentNegotiationManager.favorParameter:true}" />
		<property name="parameterName" value="${core.openApi.contentNegotiationManager.parameterName:format}" />
		<property name="ignoreAcceptHeader" value="${core.openApi.contentNegotiationManager.ignoreAcceptHeader:false}" />
		<property name="useJaf" value="${core.openApi.contentNegotiationManager.useJaf:false}"/>		
		<property name="defaultContentType" value="${core.openApi.contentNegotiationManager.defaultContentType:}" />
        <property name="defaultContentTypeStrategy" ref="${core.openApi.contentNegotiationManager.defaultContentTypeStrategy:nullBean}" /><!--favorParameter、defaultContentType为false时可开启  -->
		<property name="mediaTypes">
            <map>
				<entry key="json" value="application/json;charset=UTF-8" />
				<entry key="xml" value="application/xml;charset=UTF-8" />
				<entry key="html" value="text/html;charset=UTF-8" />
				<!-- <entry key="file" value="application/octet-stream" />
				<entry key="image" value="image/*" /> -->
				<entry key="enc_json" value="text/enc_json;charset=UTF-8" />
			</map>
        </property>
	</bean>
	
	<!-- <mvc:annotation-driven /> -->
	<!-- 如果没指定content-negotiation-manager熟悉,则会默认实例化名为mvcContentNegotiationManager的bean -->
	<mvc:annotation-driven validator="validator" content-negotiation-manager="contentNegotiationManager"><!--    -->
		<!-- <mvc:message-converters register-defaults="true" >
			<ref bean="mappingJackson2HttpMessageConverter" />
	        <ref bean="mappingJackson2XmlHttpMessageConverter" />
		</mvc:message-converters> -->
		<!-- <mvc:message-converters register-defaults="true">
            <ref bean="stringHttpMessageConverter" />
        	<ref bean="mappingJackson2HttpMessageConverter" />
        	<ref bean="mappingJackson2XmlHttpMessageConverter" />
  		</mvc:message-converters> -->
  		<mvc:argument-resolvers>
  			<bean class="cn.meteor.module.core.openApi.handler.RestRequestResponseBodyMethodProcessor"><!-- 提供支持RestRequestBody注解 -->
            	<constructor-arg ref="messageConverters" />
            	<constructor-arg ref="requestResponseBodyAdvice" /><!-- jsonp -->
            </bean>
  		</mvc:argument-resolvers>
  		 <mvc:return-value-handlers>
  		 
            <!-- <bean class="org.springframework.web.servlet.mvc.method.annotation.ModelAndViewMethodReturnValueHandler"></bean> -->
            <!-- <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor"></bean> -->
            <!-- 提供支持RestResponseBody注解 --><!-- jsonp -->
            <bean class="cn.meteor.module.core.openApi.handler.RestRequestResponseBodyMethodProcessor">
            	<constructor-arg ref="messageConverters" />
            	<constructor-arg ref="requestResponseBodyAdvice" />
            </bean>
        </mvc:return-value-handlers>
	</mvc:annotation-driven>
	
	<bean id="fileBaseAppSecretManager"  class="cn.meteor.module.core.openApi.secret.impl.FileBaseAppSecretManager">
		<property name="propertiesFilePath" value="${core.openApi.fileBaseAppSecretManager.propertiesFilePath:openApi/appSecret.properties}"  />
	</bean>
	
	<alias alias="appSecretManager" name="${core.openApi.appSecretManager.beanName:fileBaseAppSecretManager}"  />
	
</beans>




© 2015 - 2024 Weber Informatics LLC | Privacy Policy