spring-mvc.xml 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:task="http://www.springframework.org/schema/task" xmlns:mvc="http://www.springframework.org/schema/mvc"
  4. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
  5. xmlns:context="http://www.springframework.org/schema/context"
  6. xsi:schemaLocation="http://www.springframework.org/schema/beans
  7. http://www.springframework.org/schema/beans/spring-beans.xsd
  8. http://www.springframework.org/schema/context
  9. http://www.springframework.org/schema/context/spring-context-4.0.xsd
  10. http://www.springframework.org/schema/task
  11. http://www.springframework.org/schema/task/spring-task-4.0.xsd
  12. http://www.springframework.org/schema/mvc
  13. http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
  14. http://www.springframework.org/schema/websocket
  15. http://www.springframework.org/schema/websocket/spring-websocket.xsd">
  16. <!-- Scan controller -->
  17. <context:component-scan
  18. base-package="com.goafanti.*.controller;com.goafanti.common.task;com.goafanti.common.utils;
  19. com.goafanti.core.websocket" />
  20. <bean name="springContextUtils" class="com.goafanti.common.utils.SpringContextUtils" scope="singleton"></bean>
  21. <bean id="passwordUtil" class="com.goafanti.common.utils.PasswordUtil">
  22. <property name="algorithmName" value="${pwd.hash_algorithm_name}"/>
  23. <property name="hashIterations" value="${pwd.hash_iterations}"/>
  24. </bean>
  25. <!-- spring bean validator -->
  26. <bean id="validator"
  27. class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
  28. <property name="providerClass" value="org.hibernate.validator.HibernateValidator" />
  29. <property name="validationMessageSource" ref="messageSource" />
  30. </bean>
  31. <mvc:annotation-driven validator="validator" />
  32. <bean
  33. class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
  34. <property name="securityManager" ref="securityManager" />
  35. </bean>
  36. <bean id="messageSource"
  37. class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
  38. <property name="defaultEncoding" value="UTF-8"></property>
  39. <property name="basenames">
  40. <list>
  41. <value>classpath:props/error</value>
  42. </list>
  43. </property>
  44. </bean>
  45. <!-- Handles HTTP GET requests for /assets/** by efficiently serving up
  46. static resources in the ${webappRoot}/assets directory -->
  47. <!-- <mvc:resources mapping="/static/images/**" location="/WEB-INF/images/" />-->
  48. <mvc:resources mapping="/static/html/**" location="/WEB-INF/html/" />
  49. <!-- <mvc:resources mapping="/static/**" location="/WEB-INF/build/" />-->
  50. <!-- <mvc:resources mapping="/favicon.ico" location="/WEB-INF/assets/favicon.ico" />-->
  51. <!-- <mvc:resources mapping="/robots.txt" location="/WEB-INF/assets/robots.txt" />-->
  52. <bean id="templateResolver"
  53. class="org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver">
  54. <property name="prefix" value="/WEB-INF/views/" />
  55. <property name="suffix" value=".html" />
  56. <property name="templateMode" value="HTML" />
  57. <property name="characterEncoding" value="UTF-8"/>
  58. <!-- Template cache is set to false (default is true). -->
  59. <property name="cacheable" value="${template.cacheable}" />
  60. </bean>
  61. <bean id="templateEngine" class="org.thymeleaf.spring4.SpringTemplateEngine">
  62. <property name="templateResolver" ref="templateResolver" />
  63. </bean>
  64. <!-- Simple strategy: only path extension is taken into account -->
  65. <bean id="cnManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
  66. <property name="favorPathExtension" value="true"/>
  67. <property name="ignoreAcceptHeader" value="true"/>
  68. <property name="defaultContentType" value="text/html"/>
  69. <property name="mediaTypes">
  70. <map>
  71. <entry key="html" value="text/html" />
  72. <entry key="xml" value="application/xml" />
  73. <entry key="atom" value="application/atom+xml" />
  74. </map>
  75. </property>
  76. </bean>
  77. <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
  78. <property name="contentNegotiationManager" ref="cnManager"/>
  79. <property name="viewResolvers">
  80. <list>
  81. <!-- Used here for 'xml' and 'atom' views -->
  82. <bean class="org.springframework.web.servlet.view.BeanNameViewResolver">
  83. <property name="order" value="1"/>
  84. </bean>
  85. <!-- thymeleaf -->
  86. <bean class="org.thymeleaf.spring4.view.ThymeleafViewResolver">
  87. <property name="templateEngine" ref="templateEngine" />
  88. <property name="characterEncoding" value="UTF-8"/>
  89. <property name="order" value="2"/>
  90. <property name="excludedViewNames" value="*.xml" />
  91. </bean>
  92. </list>
  93. </property>
  94. </bean>
  95. <bean id="multipartResolver"
  96. class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
  97. <property name="defaultEncoding" value="UTF-8" />
  98. <!-- 不限制图片上传大小 -1 不限制 20971520-->
  99. <property name="maxUploadSize" value="20971520" />
  100. </bean>
  101. <bean
  102. class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping">
  103. </bean>
  104. <bean
  105. class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
  106. <property name="messageConverters">
  107. <list>
  108. <bean
  109. class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" />
  110. </list>
  111. </property>
  112. </bean>
  113. <bean id="exceptionResolver" class="com.goafanti.common.error.SystemExceptionResolver">
  114. <property name="exceptionMappings">
  115. <props>
  116. <prop key="org.apache.shiro.authc.UnknownAccountException">login</prop>
  117. <prop key="org.apache.shiro.authc.LockedAccountException">login</prop>
  118. <prop key="org.apache.shiro.authc.ExcessiveAttemptsException">login</prop>
  119. <prop key="org.apache.shiro.authc.IncorrectCredentialsException">login</prop>
  120. <prop key="org.apache.shiro.session.ExpiredSessionException">login</prop>
  121. <prop key="java.lang.Exception">error</prop>
  122. </props>
  123. </property>
  124. </bean>
  125. <bean id="shiroFilterUtils" class="com.goafanti.core.shiro.filter.ShiroFilterUtils" scope="singleton">
  126. <property name="appName" value="${app.name}" />
  127. </bean>
  128. </beans>