Module Configuration File
A SOFABoot project can contain multiple modules. Each module mainly includes the following two parts:
A common JAR package. The content includes:
Java code
Spring configuration file
SOFABoot submodule identification
SOFABoot-specific configurations. These unique configurations allow a JAR package to be recognized by SOFABoot, making it modular. It mainly includes the following two parts:
properties configuration file. The description is as follows:
Path: in the resources directory of the deployable module. Deployable modules are modules that are packaged using spring-boot-maven-plugin.
Naming Rule: Use a fixed name
sofa-module.properties.Configuration Content: Configure the name of the SOFABoot module and the dependencies between the modules.
Spring configuration file. The description is as follows:
Path: located in the
META-INF/springdirectory of the SOFABoot module. By default, new projects do not have spring folders. You must create them.Quantity: You can configure as many Spring XML configuration files as you want. SOFABoot will automatically load them as the Spring configuration for this module.
Detailed explanation of sofa-module.properties documents
The configuration content of the sofa-module.properties. Example:
Module-Name=com.alipay.test.biz.service.impl
Spring-Parent=com.alipay.test.common.dal
Require-Module=com.alipay.test.biz.shared
Module-Profile=devThe key corresponding to the property to be configured in the configuration file is described as follows:
Module-Name
The
Module-Nameis the name of the SOFABoot module and a unique identifier for the SOFABoot module.The uniqueness of the value must meet the following conditions:
In a SOFABoot project, the
Module-Nameof different modules must not be duplicated.If a SOFABoot module of another project is dependent on the SOFABoot module, the module name cannot be the same as that of the dependent project.
Spring-Parent
Each module has a Spring context and is isolated from each other.
Spring-Parentis mainly used to break through the Spring context of the two modules you expect to break through.Due to the limitation of Spring, the Spring-Parent of a module can only have one module. Therefore, in SOFABoot, when the Spring-Parent of one module A is set to another module B, the Spring-Parent of A is no longer the root context Root ApplicationContext , but it finally depends indirectly on the root context and can indirectly access the Bean in the root context.
For more information about the role of Spring-Parent, see Spring's BeanFactory.
Require-Module
Require-Moduleare used to define the order of dependencies between modules. The values are a comma-separated list of SOFABoot module names.The module corresponding to the attribute value precedes the module corresponding to the attribute key.
In general, you do not need to configure this attribute value for the module. You can configure this key only when the Spring context has dependencies.
Configuration example:
Require-Module=com.alipay.test.biz.sharedindicates the following:This module depends on the
com.alipay.test.biz.sharedmodule.com.alipay.test.biz.sharedmodule will start the Spring context before this module.
Application example: You publish a SOFA JVM Service in module A. In the
initmethod of a bean in module b, SOFA Reference needs to be used to call this SOFA JVM Service.Assuming that module B is started before module A, the bean of module B will fail init because the JVM Service of module A is not published, thus causing the Spring context to fail to start.
Require-Modulecan be used to force the module to start before the B module.
Module-Profile: SOFABoot Profile is supported. For more information, see Module activation configuration.