zoukankan      html  css  js  c++  java
  • 升级spring&集成Redis 一 : spring3升级spring4

    1  背景

    由于项目中使用的spring版本比较低,无法很好支持某些功能的使用,于是决定将spring3升级为spring4

    2  升级spring版本

    修改前:<spring.version>3.1.1.RELEASE</spring.version>

    修改后 :<spring.version>4.3.12.RELEASE</spring.version>

    3 升级 jackson

    <jackson.version>2.9.3</jackson.version>
    <!-- jackson start-->
    <dependency>
       <groupId>com.fasterxml.jackson.core</groupId>
       <artifactId>jackson-annotations</artifactId>
       <version>${jackson.version}</version>
    </dependency>
    <dependency>
       <groupId>com.fasterxml.jackson.core</groupId>
       <artifactId>jackson-core</artifactId>
        <version>${jackson.version}</version>
     </dependency>
     <dependency>
         <groupId>com.fasterxml.jackson.core</groupId>
         <artifactId>jackson-databind</artifactId>
         <version>${jackson.version}</version>
    </dependency>
    <!-- jackson end-->
    

      

    4 修改其他相关依赖冲突的配置

    比如:
    [ERROR]2020-03-14 16:28:08-[org.springframework.web.context.ContextLoader.initWebApplicationContext()]: Context initialization failed
    org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [com.test.common.mvc.annotation.JSONHttpMessageConverter] for bean with name 'jsonHttpMessageConverter' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: problem with class file or dependent class; nested exception is java.lang.NoClassDefFoundError: org/springframework/http/converter/json/MappingJacksonHttpMessageConverter
    	at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1388)
    
    找到引用MappingJacksonHttpMessageConverter的地方;将原来版本中的MappingJacksonHttpMessageConverter 使用新版MappingJackson2HttpMessageConverter替换
    

      

    5 请求响应格式变化

    原来在 Spring3 中默认会返回 JSON 格式,然而在 Spring4 中可能会默认返回 XML 格式

    可以在 Controller 中的 @RequestMapping 中加入 produces = "application/json",明确指定返回 JSON 格式。示例:

    @RequestMapping(value = "/login", method = RequestMethod.POST, produces = "application/json")

  • 相关阅读:
    【leetcode】1562. Find Latest Group of Size M
    【leetcode】1561. Maximum Number of Coins You Can Get
    【leetcode】1560. Most Visited Sector in a Circular Track
    Python中用format函数格式化字符串的用法
    机器学习最常用优化之一——梯度下降优化算法综述
    python学习之argparse模块
    Ubuntu14.04安装NVIDIA显卡驱动
    Anaconda使用教程
    TensorFlow0.8代码目录结构讲解
    cmake编译opencv程序
  • 原文地址:https://www.cnblogs.com/brant/p/12496709.html
Copyright © 2011-2022 走看看