Master Spring Boot 3.2.5: Maven Property Expansion & Advanced Config
This guide demonstrates how to leverage Maven resource filtering for automatic property expansion in Spring Boot 3.2.5, configure externalized settings via spring.main and system properties, customize configuration file locations, activate profiles, set parent containers, modify DispatcherServlet paths, enable Tomcat access logs, MBean registry, and generate build and Git metadata.
1. Maven automatic property expansion
Using resource filtering you can expand Maven project properties with @...@ placeholders. Example pack.yml:
pack:
app:
java-version: "java.version@"
springboot-version: "@project.parent.version@"
sourceEncoding: "@project.build.sourceEncoding@"Inject values:
@Value("${pack.app.java-version}")
private String javaVersion;
@Value("${pack.app.springboot-version}")
private String springBootVersion;
@Value("${pack.app.sourceEncoding}")
private String sourceEncoding;Result:
java-version: 17.0.9, springboot-version: 3.2.5, sourceEncoding: UTF-8Maven parent definition:
2. SpringApplication externalized configuration
Set properties under spring.main.* to externalize configuration, e.g.:
spring:
main:
web-application-type: servlet
banner-mode: offOther properties can be set programmatically:
SpringApplication app = new SpringApplication(Application.class);
app.setWebApplicationType(WebApplicationType.SERVLET);
app.setBannerMode(Mode.CONSOLE);
app.run(args);File‑based configuration overrides code settings.
3. Changing configuration file location and name
Use system properties or environment variables: spring.config.name (or SPRING_CONFIG_NAME) – default
application spring.config.location(or SPRING_CONFIG_LOCATION) – path or URL of the file
Example startup commands:
java -Dspring.config.name=app -jar MyApp.jar
java -Dspring.config.location=d:\xxxooo\app.yml -jar MyApp.jar4. Activating profiles
Specify active profiles in application.yml:
spring:
profiles:
active:
- devIf no profile is set, the default profile is used; you can change it with:
spring:
profiles:
default: devProfile activation image:
5. Setting parent and child containers
SpringApplicationBuilder builder = new SpringApplicationBuilder(Application.class);
builder.child(ChildConfig.class);
builder.parent(ParentConfig.class);
builder.build().run(args);6. Customizing DispatcherServlet path
spring:
mvc:
servlet:
path: /apiProgrammatic registration:
@Bean(name = DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME)
public DispatcherServletRegistrationBean dispatcherServletRegistration() {
DispatcherServlet dispatcherServlet = new DispatcherServlet();
DispatcherServletRegistrationBean registration = new DispatcherServletRegistrationBean(dispatcherServlet, "/api");
registration.setName("dispatcherServlet");
registration.setLoadOnStartup(0);
return registration;
}7. Configuring access logs
server:
tomcat:
basedir: "pack-tomcat"
accesslog:
enabled: true
pattern: "%t %a %r %s (%D microseconds)"Logs are written under the Tomcat base directory; you can change the directory with the basedir setting.
8. Enabling Tomcat MBean registry
server:
tomcat:
mbeanregistry:
enabled: trueAfter enabling, MBean metrics are visible via JConsole.
9. Generating build information
Add the Spring Boot Maven plugin with the build-info goal:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>3.2.5</version>
<executions>
<execution>
<goals>
<goal>build-info</goal>
</goals>
</execution>
</executions>
</plugin>10. Generating Git information
Include the Git commit ID plugin:
<plugin>
<groupId>io.github.git-commit-id</groupId>
<artifactId>git-commit-id-maven-plugin</artifactId>
</plugin>After building, a git.properties file is packaged in the JAR and can be inspected for repository state.
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.
Spring Full-Stack Practical Cases
Full-stack Java development with Vue 2/3 front-end suite; hands-on examples and source code analysis for Spring, Spring Boot 2/3, and Spring Cloud.
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.
