Spring3 升级Spring 4

周末加班,想把spring3升级到spring4。 列一下遇到的坑

更换spring版本为

4.2.3

<dependency>
    <groupId>org.springframeworkgroupId>
    <artifactId>spring-coreartifactId>
    <version>4.2.3.RELEASEversion>
dependency>

加入spring support:

3中很多的扩展内容不需要引入support,但是4中分离的更彻底了,如果不分离,会很多ClassNotFound

<dependency>
    <groupId>org.springframeworkgroupId>
    <artifactId>spring-context-supportartifactId>
    <version>4.2.3.RELEASEversion>
dependency>

更换springmvc jackson依赖

spring mvc中如果过返回json需要依赖jackson的jar包,但是他升级到了2, 以前是codehaus.jackson,现在换成了fasterxml.jackson

<dependency>      
    <groupId>com.fasterxml.jackson.coregroupId>
    <artifactId>jackson-coreartifactId>
    <version>2.7.0version>
dependency>
<dependency>                
    <groupId>com.fasterxml.jackson.coregroupId>
    <artifactId>jackson-databindartifactId>
    <version>2.7.0version>
dependency>

同时修改spring mvc的配置文件:

<bean
        class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
        <property name="messageConverters">
            <list>
                 <ref bean="stringHttpMessageConverter" />  
                <bean
                    class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
                bean>
            list>
        property>
    bean>

    <bean id="stringHttpMessageConverter"
        class="org.springframework.http.converter.StringHttpMessageConverter">
        <property name="supportedMediaTypes">
            <list>
                <value>text/plain;charset=UTF-8value>
            list>
        property>
    bean>

修改Spring配置文件的xsd

修改Spring使用的quartz

<dependency>
                <groupId>org.quartz-schedulergroupId>
                <artifactId>quartzartifactId>
                <version>2.2.2version>
            dependency>

同时修改quartz的配置文件:

<bean id="lctWorkTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
        <property name="jobDetail">
            <bean class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
                
                <property name="targetObject">
                    <ref bean="pushMessageWork" />
                property>
                
                <property name="targetMethod">
                    <value>workvalue>
                property>
            bean>
        property>
        
        <property name="cronExpression">
            <value>0/30 * * * * ?value>
        property>
    bean>

    
    <bean id="startQuertz" lazy-init="false" autowire="no"
        class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="triggers">
            <list>
                <ref bean="lctWorkTrigger" />
            list>
        property>
    bean>

你可能感兴趣的:(wzj,Spring)