Spring版本从3.0.3.Release升级到4.0.3.Release

时间:2018-07-27 18:56:39

标签: spring upgrade

我正在尝试将Spring版本从3.0.3.RELEASE升级到4.0.3.RELEASE 在尝试这样做时,我遇到了一些不赞成使用的类,如CommonsClientHttpRequestFactory,我尝试了Internet / stackoverflow上几乎所有可用的RestTemplate工厂(基本REST身份验证)版本,但是没有运气,没有任何效果。

这些我已经尝试过了 RestTemplate with Basic Auth in Spring 3.1 Basic Authentication with RestTemplate (3.1) Spring 4.0.0 basic authentication with RestTemplate

xmlconversion出问题了吗?

请检查以下文件并提出您的意见,我需要更新。

application-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=[this is not a 
link]"http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:p="http://www.springframework.org/schema/p"
xmlns:mvc="http://www.springframework.org/schema/mvc" 
xmlns:context="http://www.springframework.org/schema/context"
xmlns:oxm="http://www.springframework.org/schema/oxm" 
xmlns:util="http://www.springframework.org/schema/util"
xmlns:jee="http://www.springframework.org/schema/jee" 
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation= http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/mvc 
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/util 
http://www.springframework.org/schema/util/spring-util-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/oxm 
http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd
http://www.springframework.org/schema/jee 
http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
http://www.springframework.org/schema/aop 
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd >

<mvc:annotation-driven />
<!--
    Instantiating the AbstractBeanConfigurerAspect for IoC on AspectJ
    created instances
-->

<context:spring-configured />

<bean id="userActivityAspects" class="com.purelife.provider.tnt.web.util.UserActivityAspects"
    factory-method="aspectOf">
    <property name="userActivityManager" ref="userActivityManager" />
</bean>

<bean id="contentRetriever" class="com.purelife.stellentclient.ContentRetriever">
    <property name="contentManager" ref="contentManager" />
</bean>

<bean id="dozerBeanMapper" class="org.dozer.DozerBeanMapper">
    <property name="mappingFiles">
        <list>
            <value>GlobalConfig.xml</value>
            .
            .
            .
        </list>
    </property>
</bean>

<bean id="viewResolver"
    class="org.springframework.web.servlet.view.tiles2.TilesViewResolver">
    <property name="viewClass"
        value="org.springframework.web.servlet.view.tiles2.TilesView" />
</bean>

<bean class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
    <property name="definitions" value="/WEB-INF/tiles-def.xml" />
</bean>

<bean class="org.springframework.oxm.xmlbeans.XmlBeansMarshaller"
    id="xmlBeansMarshaller" />


<bean id="marshallingLoggerHandler" class="com.purelife.spring.utils.MarshallingLoggerHandler">
    <property name="marshaller" ref="xmlBeansMarshaller" />
    <property name="unmarshaller" ref="xmlBeansMarshaller" />
    <property name="message" value="call to services" />
    <property name="formatXML" value="true" />
</bean>
<bean id="loggingMarshaller" class="com.purelife.spring.utils.LoggerProxyFactory"
    factory-method="proxyMarshaller">
    <constructor-arg ref="marshallingLoggerHandler" />
</bean>
<bean id="loggingUnmarshaller" class="com.purelife.spring.utils.LoggerProxyFactory"
    factory-method="proxyUnmarshaller">
    <constructor-arg ref="marshallingLoggerHandler" />
</bean>


<bean id="marshallingHttpMessageConverter"
    class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
    <property name="marshaller" ref="loggingMarshaller" />
    <property name="unmarshaller" ref="loggingUnmarshaller" />
</bean>

<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">

<!-- one of the properties available; the maximum file size in bytes -->
<!--<property name="maxUploadSize" value="3221225472"/>-->
</bean>


<!--                                                                      -->
<!-- Configuration for encryptor, based on environment variables.         -->
<!--                                                                      -->

<bean id="systemPropertiesConfiguration" class="org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig">
    <property name="algorithmSysPropertyName" value="PROPERTY_ENCRYPTION_ALGORITHM" />
    <property name="passwordSysPropertyName" value="tnt_ENCRYPTION_PASSWORD" />
</bean>

<!--                                                                      -->
<!-- The will be the encryptor used for decrypting configuration values.  -->
<!--                                                                      -->
<bean id="configurationEncryptor" class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor">
    <property name="config" ref="systemPropertiesConfiguration" />
    <property name="provider">
        <bean id="bouncyCastleProvider" class="org.bouncycastle.jce.provider.BouncyCastleProvider" ></bean>
    </property>
</bean>

<bean class="org.jasypt.spring.properties.EncryptablePropertyPlaceholderConfigurer">
    <constructor-arg ref="configurationEncryptor" />
    <property name="locations">
        <list>
        <value>WEB-INF/classes/env/${application.environment}/deployment/config/services.properties</value>
        <value>WEB-INF/classes/env/${application.environment}/deployment/config/siteminder.properties</value>
        <value>WEB-INF/classes/versions.properties</value>
      </list>
    </property>
    <property name="systemPropertiesModeName">
        <value>SYSTEM_PROPERTIES_MODE_OVERRIDE</value>
    </property>
</bean>


<bean id="commonsClientHttpRequestFactory" class="org.springframework.http.client.CommonsClientHttpRequestFactory" />

<bean id="restTemplateFactory" class="com.purelife.provider.tnt.web.util.RestTemplateFactory">
    <property name="commonsClientHttpRequestFactory" ref="commonsClientHttpRequestFactory" />
    <property name="messageConverters">
        <util:list>
            <ref bean="marshallingHttpMessageConverter" />
        </util:list>
    </property>
</bean>

<bean id="restTemplate" factory-bean="restTemplateFactory"
    factory-method="getInstance">
    <constructor-arg name="host" value="${ws.host}" />
    <constructor-arg name="port" value="${ws.port}" />
    <constructor-arg name="username" value="${ws.username}" />
    <constructor-arg name="password" value="${ws.password}" />
</bean>


<bean id="maintainManagerAvail" class="com.purelife.provider.tnt.web.managers.MaintainManagerAvail">
    <property name="dozerBeanMapper" ref="dozerBeanMapper" />
    <property name="restTemplate" ref="restTemplate" />
    <property name="getOrgProgramUserDetailsAvailURL" value="${url.prefix}${getOrgProgramUserDetailsAvail}" />
    <property name="addOrgProgramUserDetailsAvailURL" value="${url.prefix}${addOrgProgramUserDetailsAvail}" />
    <property name="deleteOrgProgramUserDetailsAvailURL" value="${url.prefix}${deleteOrgProgramUserDetailsAvail}" />
    <property name="getUserRoleProgramAvailURL" value="${url.prefix}${getUserRoleProgramAvail}" />
    <property name="getOrgProgGrpNPIDetailsURL" value="${url.prefix}${getOrgProgGrpNPIDetails}" />
    <property name="getAvailityUserRoleURL" value="${url.prefix}${getAvailityUserRole}" />
    <property name="panelUserListURL" value="${url.prefix}${panelUserList}" />
</bean>

<bean id="messageSource"
    class="org.springframework.context.support.ResourceBundleMessageSource">
    <property name="basenames">
        <list>
            <value>tntmessage</value>
            <value>admin/messages</value>
            <value>email</value>            
        </list>
    </property>
</bean>



 <bean id="servicesProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
    <property name="location" value="WEB-INF/classes/env/${application.environment}/deployment/config/services.properties"/>
</bean>


<context:component-scan base-package="com.purelife.provider.tnt" />

<!--  Start Configuration Send Mail -->
<!-- and configure the MailSender with the authenticated session -->
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
    <property name="host" value="smtp.purelife.com" />
    <property name="port" value="25" />
    <property name="username" value="" />
    <property name="password" value="" />
</bean>
<!--  End Configuration Send Mail -->

<bean class="org.springframework.web.context.support.ServletContextAttributeExporter">
    <property name="attributes">
        <map>
            <entry key="tntVersion" value="${tntVersion}" />
            <entry key="NEenableKeepalive" value="true" />
            <entry key="CEenableKeepalive" value="true" />
            <entry key="VAenableKeepalive" value="true" />
            <entry key="NYenableKeepalive" value="true" />
            <entry key="WTenableKeepalive" value="true" />
        </map>
    </property>
</bean>

  <bean id="scanEngine" class="com.symantec.scanengine.api.ScanEngine" factory-method="createScanEngine">
    <constructor-arg ref="scanEngineInfo"/>
    <constructor-arg value="${readWriteTime}"/> <!--socket read timeout in milliseconds -->
    <constructor-arg value="${failRetryTime}"/> <!--time in milliseconds used by load balancing algorithm to decide the amount of time for which a failed scan engine in the list should be ignored for connection  -->
  </bean>

   <bean id="scanEngineInfo" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
         <property name="targetClass"><value>com.purelife.spring.utils.SurveyUtility</value></property>
         <property name="targetMethod"><value>getEngineInfo</value></property>
         <property name="arguments">
             <list>
               <value>${scanEngines}</value>
             </list>
         </property>             
   </bean>    

RestemplateFactory.java

package com.purelife.provider.tnt.web.util;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.springframework.http.client.CommonsClientHttpRequestFactory;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.client.RestTemplate;

public class RestTemplateFactory
{
private RestTemplate restTemplate = null;

private RestTemplateFactory()
{
}

private List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
private CommonsClientHttpRequestFactory commonsClientHttpRequestFactory;

public void setMessageConverters(
        List<HttpMessageConverter<?>> messageConverters)
{
    this.messageConverters = messageConverters;
}

public void setCommonsClientHttpRequestFactory(
        CommonsClientHttpRequestFactory commonsClientHttpRequestFactory)
{
    this.commonsClientHttpRequestFactory = commonsClientHttpRequestFactory;
}

public RestTemplate getInstance(String host, int port, String username,
        String password)
{
    commonsClientHttpRequestFactory.getHttpClient().getState()
            .setCredentials(new AuthScope(host, port, AuthScope.ANY_REALM),
                    new UsernamePasswordCredentials(username, password));
    restTemplate = new RestTemplate(commonsClientHttpRequestFactory);
    restTemplate.setMessageConverters(messageConverters);
    return restTemplate;
}
}

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<dependencies>
<!-- Local jars -->
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>  
<dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.3</version>
    </dependency>
    <dependency>
  <groupId>org.jasypt</groupId>
  <artifactId>jasypt</artifactId>
  <version>1.7.1</version>
  <scope>compile</scope>
 </dependency>


<dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.6.3</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.6.3</version>
    </dependency>

<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.8.1</version>
    </dependency>


<dependency>
  <groupId>commons-logging</groupId>
  <artifactId>commons-logging</artifactId>
        <version>1.2</version>
</dependency>
<dependency>
  <groupId>log4j</groupId>
  <artifactId>log4j</artifactId>
  <version>1.2.16</version>
</dependency>

<!-- Spring -->
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-core</artifactId>
  <version>3.0.3.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-context-support</artifactId>
  <version>3.0.3.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-context</artifactId>
  <version>3.0.3.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-web</artifactId>
  <version>3.0.3.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-test</artifactId>
  <version>3.0.3.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-jdbc</artifactId>
  <version>3.0.3.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-webmvc</artifactId>
  <version>3.0.3.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-oxm</artifactId>
  <version>3.0.3.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-aop</artifactId>
  <version>3.0.3.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-asm</artifactId>
  <version>3.0.3.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-beans</artifactId>
  <version>3.0.3.RELEASE</version>
</dependency>
 <dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-aspects</artifactId>
  <version>3.0.3.RELEASE</version>
</dependency>

<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>servlet-api</artifactId>
  <version>2.5</version>
  <scope>provided</scope>
</dependency>
<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>jsp-api</artifactId>
  <version>2.0</version>
  <scope>provided</scope>
</dependency>

<dependency>
  <groupId>javax.mail</groupId>
  <artifactId>mail</artifactId>
  <version>1.4.1</version>
</dependency>
<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>4.7</version>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>net.sf.dozer</groupId>
  <artifactId>dozer</artifactId>
  <version>5.2.1</version>
</dependency>
<dependency>
  <groupId>xmlbeans</groupId>
  <artifactId>xbean</artifactId>
  <version>2.5.0</version>
  <scope>system</scope>
  <systemPath>${basedir}/../external-jar/xbean-2.5.0.jar</systemPath>
</dependency>
<dependency>
  <groupId>xmlbeans</groupId>
  <artifactId>xbean_xpath</artifactId>
  <version>2.5.0</version>
  <scope>system</scope>
  <systemPath>${basedir}/../external-jar/xbean_xpath-2.5.0.jar</systemPath>
</dependency>

<dependency>
  <groupId>xmlbeans</groupId>
  <artifactId>xmlpublic</artifactId>
  <version>2.5.0</version>
  <scope>system</scope>
  <systemPath>${basedir}/../external-jar/xmlpublic-2.5.0.jar</systemPath>
</dependency>
<dependency>
  <groupId>commons-lang</groupId>
  <artifactId>commons-lang</artifactId>
  <version>2.5</version>
</dependency>

<dependency>
  <groupId>commons-beanutils</groupId>
  <artifactId>commons-beanutils</artifactId>
        <version>1.9.3</version>
</dependency>
<!-- Apache Commons Upload --> 
<dependency>
    <groupId>commons-fileupload</groupId>
    <artifactId>commons-fileupload</artifactId>
    <version>1.1.1</version>
</dependency>
<dependency>
    <groupId>commons-io</groupId>
    <artifactId>commons-io</artifactId>
    <version>1.2</version>
</dependency>


<!-- Tiles defs -->
<dependency>
  <groupId>org.apache.tiles</groupId>
  <artifactId>tiles-servlet</artifactId>
  <version>2.2.1</version>
  <exclusions>
    <exclusion>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging-api</artifactId>
    </exclusion>
    <exclusion>
        <groupId>org.slf4j</groupId>
        <artifactId>jcl-over-slf4j</artifactId>
    </exclusion>
  </exclusions>
</dependency>
<dependency>
  <groupId>org.apache.tiles</groupId>
  <artifactId>tiles-jsp</artifactId>
  <version>2.2.1</version>
</dependency>
<!-- Jackson JSON Mapper -->
<dependency>
  <groupId>org.codehaus.jackson</groupId>
  <artifactId>jackson-mapper-asl</artifactId>
  <version>1.4.2</version>
</dependency>

<dependency>
  <groupId>commons-dbcp</groupId>
  <artifactId>commons-dbcp</artifactId>
  <version>1.2.2</version>
</dependency>
<dependency>
  <groupId>commons-validator</groupId>
  <artifactId>commons-validator</artifactId>
  <version>1.3.0</version>
  <scope>compile</scope>
  <exclusions>
    <exclusion>
      <groupId>xml-apis</groupId>
      <artifactId>xml-apis</artifactId>
    </exclusion>
  </exclusions>
</dependency>
<dependency>
  <groupId>commons-codec</groupId>
  <artifactId>commons-codec</artifactId>
        <version>1.9</version>
</dependency>

<dependency>
  <groupId>org.aspectj</groupId>
  <artifactId>aspectjrt</artifactId>
  <version>1.6.7</version>
</dependency>


<dependency>
  <groupId>org.springframework.ws</groupId>
  <artifactId>spring-ws-core</artifactId>
        <version>2.2.0.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework.ws</groupId>
  <artifactId>spring-xml</artifactId>
        <version>2.2.0.RELEASE</version>
</dependency>
<dependency>
  <groupId>net.sf.ehcache</groupId>
  <artifactId>ehcache</artifactId>
  <version>2.1.0</version>
  <type>pom</type>
  <exclusions>
    <exclusion>
      <groupId>net.sf.ehcache</groupId>
      <artifactId>ehcache-terracotta</artifactId>
    </exclusion>
  </exclusions>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.5.11</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jcl</artifactId>
<version>1.5.11</version>
</dependency>
<dependency>
<groupId>xpp3</groupId>
<artifactId>xpp3_min</artifactId>
<version>1.1.4c</version>
</dependency>
<dependency>
<groupId>thoughtworks</groupId>
<artifactId>xstream</artifactId>
<version>1.3.1</version>
</dependency>

<plugins>
  <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <compilerArgument>-XDignore.symbol.file</compilerArgument>
      <source>1.6</source>
      <target>1.6</target>
    </configuration>
  </plugin>

<!-- Copying the system dependenies to lib -->
  <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
    <execution>
        <id>copy-dependencies</id>
        <phase>compile</phase>
        <goals>
             <goal>copy-dependencies</goal>
        </goals>
        <configuration>
             <outputDirectory>${project.build.directory}/${project.artifactId}-${project.version}/WEB-INF/lib</outputDirectory>
             <includeScope>system</includeScope>
        </configuration>
    </execution>
</executions>
</plugin> 

  <!-- AsjpectJ compiler -->
  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>aspectj-maven-plugin</artifactId>
    <version>1.8</version>
    <configuration>
      <complianceLevel>1.6</complianceLevel>
      <!-- add dependencies to also be have aspects added -->


    </configuration>

  </plugin>

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
      <skipTests>true</skipTests>
    </configuration>
  </plugin>

0 个答案:

没有答案