fix: PROD-INSIGHTS-API-26 support external servlet container#228
fix: PROD-INSIGHTS-API-26 support external servlet container#228
Conversation
WalkthroughEnables deployment in an external servlet container by making InsightsApiApplication extend SpringBootServletInitializer and adding a configure(SpringApplicationBuilder) method while retaining the existing SpringApplication.run(...) main entry point. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant User
participant JVM
participant InsightsApiApplication
participant SpringBoot
participant ServletContainer
alt Standalone execution (unchanged)
User->>JVM: run main()
JVM->>InsightsApiApplication: main(String[] args)
InsightsApiApplication->>SpringBoot: SpringApplication.run(InsightsApiApplication.class, args)
SpringBoot-->>User: Application started (JAR)
else External servlet container (new path)
ServletContainer->>InsightsApiApplication: initialize via SpringBootServletInitializer
InsightsApiApplication->>InsightsApiApplication: configure(SpringApplicationBuilder)
InsightsApiApplication->>SpringBoot: application.sources(InsightsApiApplication.class)
SpringBoot-->>ServletContainer: Application initialized (WAR)
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes ✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
src/main/java/io/kontur/insightsapi/InsightsApiApplication.java(1 hunks)
🔇 Additional comments (1)
src/main/java/io/kontur/insightsapi/InsightsApiApplication.java (1)
13-13: LGTM: correct hook for external servlet containersExtending SpringBootServletInitializer is the standard approach for WAR deployment on Spring Boot 2/3 and works alongside the existing main method.
| import org.springframework.boot.builder.SpringApplicationBuilder; | ||
| import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; |
There was a problem hiding this comment.
💡 Verification agent
🧩 Analysis chain
External container support requires WAR packaging and provided container starter
Imports look correct. To actually run in an external servlet container, verify the Maven setup: packaging should be war and your servlet container starter (tomcat/jetty/undertow) should be scope provided. Otherwise you may end up with an embedded container conflict or an undeployable artifact.
Run this to check:
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "Packaging (expect: war):"
rg -nP '<packaging>\s*(war|jar)\s*</packaging>' pom.xml || echo "No <packaging> tag found"
echo -e "\nServlet container starters present:"
rg -nP 'spring-boot-starter-(tomcat|jetty|undertow)' pom.xml -n -C2 || true
echo -e "\nProvided-scope check for container starters (expect: provided):"
rg -nP '(?s)<dependency>\s*<groupId>org\.springframework\.boot</groupId>\s*<artifactId>spring-boot-starter-(tomcat|jetty|undertow)</artifactId>.*?<scope>provided</scope>.*?</dependency>' pom.xml -n -C2 || echo "No provided-scope container starter found"Length of output: 799
pom.xml needs WAR packaging and provided-scope servlet starter
pom.xml currently has no <packaging>war</packaging> (defaults to JAR) and no external servlet container starter. To deploy as a WAR, add under <project>:
<packaging>war</packaging>and include, for example:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>🤖 Prompt for AI Agents
In src/main/java/io/kontur/insightsapi/InsightsApiApplication.java around lines
5 to 6, the project is preparing for WAR deployment (imports of
SpringBootServletInitializer) but pom.xml is still configured for JAR; update
pom.xml to set <packaging>war</packaging> under the <project> element and add
the servlet container starter with provided scope (e.g.,
spring-boot-starter-tomcat with <scope>provided</scope>) so the app can be
deployed as a WAR to an external servlet container.
| /** | ||
| * Allow running the application inside an external servlet container. | ||
| */ | ||
| @Override | ||
| protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { | ||
| return application.sources(InsightsApiApplication.class); | ||
| } |
There was a problem hiding this comment.
🧹 Nitpick (assertive)
configure(...) is correct; tighten the Javadoc (nit)
Implementation is standard. Consider sharpening the Javadoc to clarify WAR/traditional deployment context.
- /**
- * Allow running the application inside an external servlet container.
- */
+ /**
+ * Configure the application for traditional (WAR) deployment to an external Servlet 3.0+ container.
+ */📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| /** | |
| * Allow running the application inside an external servlet container. | |
| */ | |
| @Override | |
| protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { | |
| return application.sources(InsightsApiApplication.class); | |
| } | |
| /** | |
| * Configure the application for traditional (WAR) deployment to an external Servlet 3.0+ container. | |
| */ | |
| @Override | |
| protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { | |
| return application.sources(InsightsApiApplication.class); | |
| } |
🤖 Prompt for AI Agents
In src/main/java/io/kontur/insightsapi/InsightsApiApplication.java around lines
15 to 21, the configure(...) method is fine but the Javadoc is vague; update the
comment to explicitly state that this override enables running the Spring Boot
application as a WAR in an external servlet container (traditional servlet
deployment) by providing the SpringApplicationBuilder source, mentioning
WAR/traditional deployment context and why it's needed (e.g., when deploying to
Tomcat/Jetty as a WAR).
Summary
Testing
make precommit(fails: No rule to make target 'precommit')mvn -q test(fails: Non-resolvable parent POM; could not transfer artifact)https://chatgpt.com/codex/tasks/task_e_68b888459d3c832481b164230e77ddce
Summary by CodeRabbit