Upgrade-related issues

更新时间:
复制 MD 格式

This topic summarizes common problems that occur in SOFABoot version upgrades and their solutions.

What steps are prepared before the upgrade

JDK 7 and Maven 3.2.5 must be installed before upgrading. For more information about how to install SOFABoot, see Configure the SOFABoot environment.

How to activate different environment configurations

If you need to provide different configurations in different environments (such as development environment, test environment, pre-release environment, and production environment), you can add the following JVM startup parameters when starting the SOFABoot application:

-Dspring.profiles.active=${workspace_name}

For more information, see Technology Stack User Guide.

After compiling, how to run locally

Execute the following orders under Engineering root directory:

  1. mvn clean install

  2. java -jar ./target/${file.name}-executable.jar (use java -jar command to run a Fat Jar, and deploy applications on SOFAStack in this way)

Of course, during local development, you can directly use the main function to start the entire application.

For more information, see On-premises compilation.

How to use placeholders

You can use configuration files to control the configurations of all common beans.

The SOFARPC middleware is used as an example. You can configure placeholders for test-url as follows:

<sofa:reference id="sampleRpcService"
interface="com.alipay.sofaboot.serverone.facade.rpc.SampleRpcService">
    <sofa:binding.tr>
        <sofa:global-attrstest-url="${test.url}"/>
    </sofa:binding.tr>
</sofa:reference>

How to access sensitive endpoints that are disabled by default (Sensitive Endpoints)

SOFABoot 2.5.0 and later resolve the security risk caused by excessive information exposure of endpoints. By default, some endpoints with security risks are disabled. For more information about how to enable endpoints, see Spring Boot documentation.

Does SOFABoot support distributed Session

SOFABoot does not support distributed Session.

After you use the SOFABoot framework, we recommend that you manage and maintain Session based on Spring Boot. The storage solution may continue to use the OCS.

The version requirements for distributed Session middleware in SOFABoot 3.x

alipay-session is no longer supported in SOFABoot. You need to use Spring Session to replace it.

<dependency>
    <groupId>com.alipay.session</groupId>
    <artifactId>alipay-session-ocs</artifactId>
    <version>1.0.3</version>
</dependency>
<dependency>
    <groupId>com.alipay.session</groupId>
    <artifactId>alipay-session-core</artifactId>
    <version>1.0.3</version>
</dependency>

StackOverFlow error in logs

Phenomenon

You might see the following stack error in the logs:

Detected both log4j-over-slf4j.jar AND slf4j-log4j12.jar on the class path, preempting StackOverflowError:
Exceptionin thread java.lang.StackOverflowError
  at java.util.Hashtable.containsKey(Hashtable.java:306)
  at org.apache.log4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:36)
  at org.apache.log4j.LogManager.getLogger(LogManager.java:39)
  at org.slf4j.impl.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:73)
  at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:249)
  at org.apache.log4j.Category.<init>(Category.java:53)
  at org.apache.log4j.Logger..<init>(Logger.java:35)
  at org.apache.log4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:39)
  at org.apache.log4j.LogManager.getLogger(LogManager.java:39)
  at org.slf4j.impl.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:73)
  at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:249)
  at org.apache.log4j.Category..<init>(Category.java:53)
  at org.apache.log4j.Logger..<init>(Logger.java:35)
  at org.apache.log4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:39)
  at org.apache.log4j.LogManager.getLogger(LogManager.java:39)
  subsequent lines omitted...

Reason

This is due to conflicts between org.slf4j:log4j-over-slf4j and log4j:log4j.

Solution

You can delete log4j-over-slf4j dependencies from ClassPath to resolve this issue.

How to introduce Spring Boot's web container

  • spring-boot-starter-web is introduced. By default, the Web container that is dependent on and started is Tomcat. The dependency information is similar to the following:

    <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
  • If you want to use Jetty as a web container, see Spring Boot documentation.

How to handle custom filters in SOFABoot projects

The SOFABoot project does not have the web.xml of the Spring project. If the original Spring MVC web.xml configuration file has a custom configuration filter, you can refer to Spring Boot official migration Servlets, Filters, and Listeners method. You can also refer to other Spring Boot Servlet, Filter, and Listener configuration tutorials.

ConverterRegistry.addConverter error in log

Phenomenon

The following records appear in the log:

Causedby:java.lang.NoSuchMethodError:org.springframework.core.convert.converter.ConverterRegistry.addConverter(Ljava/lang/Class;Ljava/lang/Class;Lorg/springframework/core/convert/converter/Converter;)

Reason

This is due to a Spring version conflict.

Solution

The current Spring unified version is 4.3.4.RELEASE. This problem can be solved by deleting other indirectly introduced versions.

LoggerSpaceManager.getLoggerBySpace error in log

Phenomenon

The following records appear in the log:

Causedby:java.lang.NoSuchMethodError: com.alipay.sofa.common.log.LoggerSpaceManager.getLoggerBySpace(Ljava/lang/String;Lcom/alipay/sofa/common/log/SpaceId;Ljava/util/Map;)Lorg/slf4j/Logger;

Reason

Since the version of 2.2.X is ArtifactId sofa-middleware-log upgraded to sofa-common-tools, when using the version of SOFABoot 2.2.X, the conflict can be solved by ensuring that classpath depends on the sofa-common-tools (the version has been controlled and the user does not need to display the added version) and excluding sofa-middleware-log dependencies.

Solution

Delete the following indirect dependencies:

<dependency>
      <groupId>com.alipay.sofa.common.log</groupId>
      <artifactId>sofa-middleware-log</artifactId>
</dependency>

and introduce the following dependencies:

<dependency>
     <groupId>com.alipay.sofa.common</groupId>
     <artifactId>sofa-common-tools</artifactId>
</dependency>

After SOFALite application is upgraded to SOFABoot 3.2.2, the application fails to start

Phenomenon

The following error is reported:

Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException:Couldnot resolve placeholder 'spring.application.name'in value "${spring.application.name}"

Reason

There is a problem with the profile configuration in the project.

Solution

Adjust the Profile configuration in Build in the pom.xml file of the module where the main function is located. For more information, see Technology Stack User Guide and the build content of the standard demo.

After you upgrade the RPC service provider and consumer engineering from SOFABoot 2.2.5 to 3.2.2, an error is reported when you call the RPC service

Phenomenon

The following error is reported:

com.alipay.remoting.exception.DeserializationException:Server deserialize request exception!

Reason

Hessian package conflict.

Solution

Print the maven tree of the server and client, and compare it with the maven tree of the standard demo. Focus on the netty, protobuf, typesafe, and hessian versions. If the versions are different, we recommend that you upgrade the version.

SOFAMVC is not supported in SOFABoot 3.x. How to implement migration upgrade

Solution

The following two scenarios are supported:

  • Scenario using Spring MVC + security package (recommend).

  • SOFABoot is temporarily upgraded to 3.3.1 to support SOFAMVC, but compatibility issues may occur.

Invalid bean definition with name dataSource error occurs after SOFABoot 2.2.5 is upgraded to SOFABoot 3.2.1

Phenomenon

The following error message appears:

Invalid bean definition with name 'dataSource'definedinclass path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]:@Bean definition illegally overridden by existing bean definition:Generic bean:class[com.alipay.zdal.adapter.sofa.spring.ZdalDatasourceFactoryBean]; scope=;abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null

Reason

Judging from the error message, it may be that the Hikari package conflicts with the ZDAL package.

Solution

If the project does not use Hikari, you can try to exclude the Hikari package.