Mastering Service Naming and Environment Configuration with Mica-Launcher
This article explains why naming conventions and environment handling are crucial in micro‑service projects, introduces the mica‑launcher tool for customizing service names and environments, and provides practical guidelines, code examples, and best‑practice recommendations for Java Spring Boot back‑end development.
Preface
In micro‑service development, conventions are often more important than code. The mica-launcher customizes service name and environment handling, making development faster and more convenient.
Service Name Conventions
A good service name should be self‑explanatory. Two‑level naming for small teams (e.g., user-api) and three‑level naming for multiple teams (e.g., mica-user-api) where the first level is the team name.
Level 1: Team name (for multi‑team)
Level 2: Service name
Level 3: Service type
Environment Division
Vision
The launcher’s mission is to allow a JAR to start in any environment without excessive configuration, reducing learning cost and enabling rapid onboarding.
Environments
dev (development), test (testing), ontest (online testing), prod (production). Default is dev.
Environment Variable Configuration
Background Story
The initial prototype of mica-launcher appeared in JFinal projects to handle Jetty during development and Tomcat in production. It was later redesigned for Spring Boot to simplify service environment handling.
Using mica-launcher
Compared with the native Spring Boot launcher, mica-launcher adds a mandatory service‑name parameter, which is crucial in micro‑services.
Maven
<dependency>
<groupId>net.dreamlu</groupId>
<artifactId>mica-launcher</artifactId>
</dependency>Gradle
implementation "net.dreamlu:mica-launcher"Example Spring Boot entry point:
@SpringBootApplication
public class MicaExampleApplication {
public static void main(String[] args) {
MicaApplication.run("mica-example", MicaExampleApplication.class, args);
}
}Note: When using mica-launcher, combine it with mica-test for unit testing.
Automated Configuration
Inject MicaProperties to read variables such as env or custom mica.prop entries defined in configuration files.
mica.env (default dev) – read‑only environment variable.
mica.is-local (default false) – indicates local development.
mica.prop – custom properties prefixed with mica.prop..
Custom configuration example
mica:
prop:
site-name: 如梦技术
site-url: https://www.dreamlu.netReading configuration
@Autowired
private MicaProperties properties;
public boolean savePost() {
String siteName = properties.get("site-name");
String siteUrl = properties.get("site-url");
// ...
}Launcher Plugin Extension
The launcher can load extensions such as mica-log4j2 via Java SPI.
LauncherService Interface
/**
* Launcher extension for component discovery
*/
public interface LauncherService {
/**
* Process SpringApplicationBuilder during startup
*/
void launcher(SpringApplicationBuilder builder, Environment env,
String appName, String profile, boolean isLocalDev);
}SPI file
Place a file at META-INF/services/net.dreamlu.mica.launcher.LauncherService containing the fully qualified class name of the implementation, e.g., net.dreamlu.mica.log.LogLauncherServiceImpl.
Best Practices
Use the predefined environment variable ${mica.env} as a placeholder in configuration files, allowing domain names to be switched per environment.
Example domain configuration
config-dev.dreamlu.vip
config-test.dreamlu.vip
...Spring Cloud Config example
spring:
cloud:
consul:
host: https://config-${mica.env}.dreamlu.vip
port: 8500
config:
format: yamlOpen‑Source Recommendations
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Architecture Diary
Committed to sharing original, high‑quality technical articles; no fluff or promotional content.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
