SpringMVC core configuration file sample and springmvc sample
<? 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: tx = "http://www.springframework.org/schema/tx" xmlns: context = "http://www.springframework.org/schema/context" xmlns: mvc = "http://www.springframework.org/schema/mvc" xsi: schemaLocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans -3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd "> <! -- Automatically scans packages and can write multiple --> <context: component-scan base-package = "com. xxx, com. xxx. session, com. xxx. xxx "> </context: component-scan> <! -- Multi-view Processor --> <bean class = "com. xxx. core. web. mixedViewResolver "> <property name =" resolvers "> <map> <entry key =" jsp "> <bean class =" org. springframework. web. servlet. view. internalResourceViewResolver "> <property name =" prefix "value ="/WEB-INF/jsp/"/> <property name =" viewClass "value =" org. springframework. web. servlet. view. jstlView "> </property> </bean> </entry> <entry key =" ftl "> <bean class =" org. springframe Work. web. servlet. view. freemarker. freeMarkerViewResolver "> <property name =" cache "value =" true "/> <property name =" contentType "value =" text/html; charset = UTF-8 "> </property> <! -- Macro command support --> <property name = "exposeSpringMacroHelpers" value = "true"/> <property name = "viewClass" value = "org. springframework. web. servlet. view. freemarker. freeMarkerView "/> <property name =" requestContextAttribute "value =" rc "> </property> </bean> </entry> </map> </property> </bean> <! -- Freemarker config --> <bean id = "freeMarkerConfigurer" class = "org. springframework. web. servlet. view. freemarker. freeMarkerConfigurer "> <property name =" templateLoaderPath "value ="/WEB-INF/ftl/"/> <property name =" freemarkerSettings "> <props> <prop key =" template_update_delay "> 5 </prop> <prop key = "default_encoding"> UTF-8 </prop> <prop key = "locale"> zh_CN </prop> </props> </property> </bean> <! -- Log interceptor --> <bean id = "logNDCInteceptor" class = "com. xxx. core. web. LogNDCInteceptor"/> <! -- Permission interceptor --> <bean id = "myPermissionsInteceptor" class = "com. xxx. userplatform. mvc. MyPermissionsInteceptor"> </bean> <! -- RequestHelper interceptor --> <bean id = "myRequestHelperInteceptor" class = "com. xxx. core. web. MyRequestHelperInteceptor"> </bean> <! -- User Information interceptor --> <bean id = "myUserInfoInteceptor" class = "com. xxx. userplatform. mvc. MyUserInfoInteceptor"> </bean> <! -- Annotation request ing --> <bean class = "org. springframework. web. servlet. mvc. annotation. defaultAnnotationHandlerMapping "> <property name =" interceptors "> <list> <ref bean =" logNDCInteceptor "/> <! -- Log interceptor --> <ref bean = "myRequestHelperInteceptor"/> <! -- RequestHelper interceptor --> <ref bean = "myPermissionsInteceptor"/> <! -- Permission interceptor --> <ref bean = "myUserInfoInteceptor"/> <! -- User Information interceptor --> </list> </property> </bean> <bean class = "org. springframework. web. servlet. mvc. annotation. annotationMethodHandlerAdapter "> <property name =" messageConverters "> <list> <ref bean =" byteArray_hmc "/> <ref bean =" string_hmc "/> <ref bean =" resource_hmc "/> <ref bean = "source_hmc"/> <ref bean = "xmlAwareForm_hmc"/> <ref bean = "jaxb2RootElement_hmc"/> <ref bean = "jackson_hmc"/> </list> </property> </Bean> <bean id = "byteArray_hmc" class = "org. springframework. http. converter. ByteArrayHttpMessageConverter"/> <! -- Processing... --> <bean id = "string_hmc" class = "org. springframework. http. converter. StringHttpMessageConverter"/> <! -- Processing... --> <bean id = "resource_hmc" class = "org. springframework. http. converter. ResourceHttpMessageConverter"/> <! -- Processing... --> <bean id = "source_hmc" class = "org. springframework. http. converter. xml. SourceHttpMessageConverter"/> <! -- Processing... --> <bean id = "xmlAwareForm_hmc" class = "org. springframework. http. converter. xml. XmlAwareFormHttpMessageConverter"/> <! -- Processing... --> <bean id = "jaxb2RootElement_hmc" class = "org. springframework. http. converter. xml. Jaxb2RootElementHttpMessageConverter"/> <! -- Processing... --> <bean id = "jackson_hmc" class = "org. springframework. http. converter. json. MappingJacksonHttpMessageConverter"/> <! -- Process json --> <! -- Total error handling --> <bean id = "exceptionResolver" class = "org. springframework. web. servlet. handler. simpleMappingExceptionResolver "> <property name =" exceptionMappings "> <props> <! -- When the size of the uploaded file is greater than the maximum size, turn to the error page --> <prop key = "org. springframework. web. multipart. maxUploadSizeExceededException "> redirect:/uploadError. jsp </prop> </props> </property> <property name = "defaultErrorView"> <value> forward:/error. jsp </value> </property> <property name = "defaultStatusCode"> <value> 200 </value> </property> <property name = "warnLogCategory"> <value> org. springframework. web. servlet. handler. simpleMappingE XceptionResolver </value> </property> </bean> <! -- Allow access to static resource files --> <mvc: default-servlet-handler/> <! -- Data source, DBCP connection pool --> <bean id = "dataSource" class = "org. apache. commons. dbcp. basicDataSource "destroy-method =" close "> <property name =" driverClassName "value =" oracle. jdbc. driver. oracleDriver "/> <property name =" url "value =" jdbc: oracle: thin: @ 192.168.3.141: 1521: xxx "/> <property name =" username "value =" xxxdb "/> <property name =" password "value =" xxxdb "/> <property name =" initialSize "value = "2"/> <property name =" MaxActive "value =" 10 "/> <property name =" maxIdle "value =" 10 "/> <property name =" maxWait "value =" 1000 "/> <property name = "poolPreparedStatements" value = "true"/> </bean> <! -- JNDI data source <bean id = "dataSource" class = "org. springframework. jndi. jndiObjectFactoryBean "> <property name =" jndiName "> <value> jdbc/xxx </value> </property> </bean> --> <! -- JDBC template --> <bean id = "jdbcTemplate" class = "org. springframework. jdbc. core. jdbcTemplate "> <property name =" dataSource "ref =" dataSource "/> </bean> <! -- Transaction Manager --> <bean id = "transactionManager" class = "org. springframework. jdbc. datasource. dataSourceTransactionManager "> <property name =" dataSource "ref =" dataSource "/> </bean> <! -- Implement transaction management with annotations --> <tx: annotation-driven transaction-manager = "transactionManager" proxy-target-class = "true"/> <! -- Used to hold ApplicationContext. SpringContextHolder can be used. getBean ('xxxx') static method to get spring bean object --> <bean class = "com. xxxxx. springContextHolder "lazy-init =" false "/> </beans>