This topic describes how to use the SOFABoot framework to create a web project, run it locally or in the cloud, and add middleware services.
The main steps are as follows:
A Core project is similar to a Web project. For more information, see Create a project.
Create a web project
Prerequisites
Before you begin, set up the SOFABoot runtime environment. For more information, see Set up the environment.
Procedure
Creating a SOFABoot web project involves two main steps:
Follow these steps:
Create a local project
These instructions apply to projects created with SOFABoot 3.3.0 or later. To upgrade, see SOFABoot Upgrade Guide.
Open the command line interface and run the following command:
mvn archetype:generate -DarchetypeGroupId=com.alipay.sofa -DarchetypeArtifactId=sofaboot-web-archetype -DarchetypeVersion=1.0-SNAPSHOT -DarchetypeCatalog=internalWhen prompted, enter the following Maven coordinate information:
groupId: A unique identifier in the Maven repository. This is typically the reversed domain name of your company or organization. For this example, enter
com.alipay.sofa.artifactId: The name of the project or application. For this example, enter
web-app.version: The version number. The default is
1.0-SNAPSHOT. SNAPSHOT indicates that the project is an unstable, in-development version. For this example, keep the default value.package: The application package name. By default, it is the same as the groupId.
# Example Define value for property 'groupId': com.alipay.sofa Define value for property 'artifactId': web-app Define value for property 'version': 1.0-SNAPSHOT Define value for property 'package': com.alipay.sofa
Confirm the Maven coordinate information.
If the information is correct, enter Y to confirm and continue creating the project.
To change the information, enter N to redefine the project properties.
# Example Confirm properties configuration: groupId: com.alipay.sofa artifactId: web-app version: 1.0-SNAPSHOT package: com.alipay.sofa Y::
After you confirm, the project is created, and the command line interface displays the following message. The project files are located in the
./webfolder in the current path.[INFO] Project created from Archetype in dir: {current_dir}/web [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 28.298 s [INFO] Finished at: 2018-01-10T23:36:19+08:00 [INFO] Final Memory: 15M/163M [INFO] ------------------------------------------------------------------------Go to the Version Guide to find the latest SOFABoot version. Then, open the main pom.xml file in the project's root directory and update the version number in the
<parent>tag. The following image shows an example:
Configure key properties
Before you deploy to the cloud, you must configure the application.properties file. For more information, see Add SOFA middleware. Follow these steps:
Go to the SOFAStack console > R&D Efficiency > Scaffolding > Step 2. The following image shows an example:
Obtain the following information:
Instance Identity: The unique identity of the application instance in the workspace. The corresponding key in the application is
com.alipay.instanceid.AntVIP: The application uses AntVIP to retrieve the server-side addresses of various components. A unique address is provided for each region. The corresponding key in the application is
com.antcloud.antvip.endpoint. The AntVIP address values for different environments are listed below.Hangzhou Gold zone:
cn-hangzhou-fin-middleware-acvip-prod.cloud.alipaycs.netShanghai non-Gold zone:
cn-shanghai-middleware-acvip-prod.cloud.alipaycs.netShanghai Gold zone:
cn-shanghai-fin-sofastack-middleware-acvip-prod.cloud.alipaycs.netHangzhou non-Gold zone:
cn-hangzhou-middleware-acvip-prod.cloud.alipaycs.net
In the Scaffolding console, click the user icon in the upper-right corner and select AccessKey Management. On the page that appears, obtain the property values for Resource Access Management (RAM). The corresponding keys in the application are:
Access Key ID:
com.antcloud.mw.accessAccess Secret:
com.antcloud.mw.secretNoteTo create an AccessKey, click Get AK. For more information, see Create an AccessKey.
Determine the run mode and environment. The following code shows an example:
run.mode=NORMAL com.alipay.env=sharedConfigure the keys and values for these properties in the
application.propertiesfile.
For more information about the SOFABoot framework configuration, project dependencies, and middleware services, see the following topics:
Import the web project into an IDE
A SOFABoot project is a standard Maven project. You can use a common Java integrated development environment (IDE), such as IntelliJ IDEA or Eclipse, for development. Follow these steps to import the SOFABoot project into your IDE:
IntelliJ IDEA
Open IntelliJ IDEA.
Import the project folder that you created.
If you are using the IDE for the first time or if you closed all projects, a welcome screen appears. On this screen, click Open, select the project folder that you created, and then click OK.
If IntelliJ IDEA automatically loads the last open project, click File > Open, select the project folder that you created, and then click OK.
Configure Maven:
Click File > Settings to open the Settings window. Navigate to the Maven configuration page in one of the following ways:
Click Build, Execution, Deployment > Build tools > Maven.
Search for the keyword Maven.
Set Maven home directory to your local Maven installation directory.
Set User Settings file to the path of your local Maven
settings.xmlfile.Click OK to close the Settings window.
After the import is complete, you can view the project structure and content in the project folder.
Eclipse
Open Eclipse.
Configure Maven:
Click Window > Preferences to open the Preferences window. Search for the keyword Maven to find the Maven configuration page.
Under Maven, select Installations and configure the Maven directory.
If your local Maven installation directory is already in the Installations list, select its checkbox.
If the directory is not in the list, click Add. In the new window, set Installation home to your local Maven installation directory. Click Finish to return, and then select the checkbox for the new directory.
Click Apply to save the configuration.
Under Maven, select User Settings and set User Settings to the path of your local Maven
settings.xmlfile.Click Apply and Close to save the configuration and close the Preferences window.
Click File > Import > Maven > Existing Maven Projects > Next. Select the project folder that you created, and then click Finish.
Compile and run locally
Follow these steps:
Start the local project in one of the following ways:
Start from the command line:
Use the cd command to navigate to the project's root directory.
Run the
mvn clean installcommand.
Start from the IDE: Run the main function in the Web module.
After the project starts successfully, open
http://localhost:8080/index.htmlin a browser. You will see the following static page content:the static page in SOFABoot based on spring-bootNoteA SOFABoot Core project does not have a user interface, so you cannot preview it locally. However, you can perform a health check by accessing
http://localhost:8080/actuator/readiness. If the status is UP, the project is running correctly.For more ways to compile and run a SOFABoot project locally, see Run locally.
Run in the cloud
For an overview of the application publishing flow, see Technology Stack and Application Publishing Flow in the Technology Stack User Guide.
For detailed steps on how to publish an application, see the Quick Start for Classic Application Service.
Add middleware services
After you create a SOFABoot project, you can add starters to the main pom.xml file to use middleware services.
For a list of middleware service types and their starter version information, see Add SOFA middleware.
For sample demos of each middleware service, see the Quick Start for the corresponding product.