SOFABoot is built on the Spring Boot framework, so you can easily migrate from Spring Boot to SOFABoot. After reading the Precautions in this article, you can follow the Migration steps to change an existing Spring Boot project to a project that uses the SOFABoot framework.
Precautions
The SOFABoot framework is built based on Spring Boot 2.1.0.RELEASE. You may change the Spring Boot version during the migration. If incompatibilities occur during the upgrade process, you can contact the technical team.
Tracer is integrated into the starter of each middleware. You do not need to add dependencies or configure the tracker.
Migration steps
You can perform the following steps to complete project migration.
In the
application.propertiesconfiguration file of the project, add basic configurations. Among them, you need to specify the following two system configuration items:spring.application.name: required. This is the application name and maintains the extension and consistency of Spring Boot.logging.path: required. Configure the output path of the log.NoteSee properties-system for a detailed description of these two configuration items.
In the
application.propertiesconfiguration file of the project, modify the middleware configuration items. For more information, see Adding SOFA middleware> properties configuration items.Open the
pom.xmlfile in the project root directory and configure the following version dependencies in theparentsection:<parent> <groupId>com.alipay.sofa</groupId> <artifactId>sofaboot-enterprise-dependencies</artifactId> <version>3.1.1</version> </parent>Introduce the starter of the corresponding middleware into the
pom.xml. For more information, see Adding SOFA middleware> Adding the starter for the relevant middleware service. In this example, SOFAREST is added. You only need to configure the following dependencies in thepom.xml:<dependency> <groupId>com.alipay.sofa</groupId> <artifactId>rest-enterprise-sofa-boot-starter</artifactId> <version>3.0.0</version> </dependency>Declare
rest facadeinterface. Example:@Path("/webapi/test") @Consumes("application/json;charset=UTF-8") @Produces("application/json;charset=UTF-8") public interface TestFacade{ @GET public String test(); }Declares the
facadeimplementation class. Example:public class TestServiceImpl implements TestFacade{ @Override public String test(){ return "test"; } }Declare the implementation class as a bean. Example:
<bean id="testServiceImpl" class="com.alipay.test.endpoint.impl.TestServiceImpl"/>Start the application.
Access the
http://localhost:8341/webapi/testin a browser and you can see the data returned by the rest interface.In the
${logging.path}/logs/tracelog/rest-server-digest.logfile, you can view the link information (tracer) log of the access.Note{logging.path}to the log output path you set in the configuration file.
For more information about other SOFA middleware integration methods, see the integration documentation of the corresponding middleware starter.