[ 
https://issues.apache.org/jira/browse/CAMEL-23080?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18061195#comment-18061195
 ] 

Claus Ibsen commented on CAMEL-23080:
-------------------------------------

**Yes, you can deploy a Spring Boot application inside an existing (external) 
Tomcat server**, and this remains a fully supported and commonly used approach 
even in 2026.

Spring Boot applications are **not** limited to their embedded Tomcat — you can 
package them as a standard **WAR** file and deploy them to an external Tomcat 
instance (or other servlet containers like Jetty, Undertow, WebLogic, etc.) 
just like a classic Spring MVC or Java EE application.

### Key Differences: Embedded vs. External Tomcat

| Aspect                  | Embedded Tomcat (default Spring Boot JAR)           
       | External Tomcat (WAR deployment)                          |
|-------------------------|------------------------------------------------------------|-----------------------------------------------------------|
| Packaging               | Executable JAR                                      
       | WAR file                                                  |
| Server startup          | `java -jar myapp.jar` — starts its own Tomcat       
       | Tomcat starts → deploys and manages your app              |
| Configuration           | Mostly via `application.properties/yaml`            
       | Tomcat-level config (ports, SSL, realms, etc.) + app config |
| Use case                | Microservices, containers (Docker/K8s), standalone 
apps    | Traditional enterprise setups, shared Tomcat instances, legacy 
migration |
| Pros                    | Zero server install, easy dev/test, fast startup    
       | Centralized management, monitoring, multiple apps per server |
| Cons                    | Less control over container lifecycle               
       | More setup steps, potential version conflicts             |

### How to Make Your Spring Boot App Deployable to External Tomcat

Here are the minimal changes (works with Spring Boot 2.x and 3.x):

1. **Change packaging to WAR** (in `pom.xml` for Maven):

   ```xml
   <packaging>war</packaging>
   ```

   Or in `build.gradle` (Gradle):

   ```groovy
   apply plugin: 'war'
   ```

2. **Mark the embedded Tomcat as provided** (so it isn't packaged into your WAR 
and avoids conflicts):

   ```xml
   <dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-web</artifactId>
   </dependency>

   <dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-tomcat</artifactId>
       <scope>provided</scope>   <!-- ← this is the key line -->
   </dependency>
   ```

3. **Extend `SpringBootServletInitializer`** (this makes your app compatible 
with servlet containers):

   ```java
   import 
org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
   import org.springframework.boot.builder.SpringApplicationBuilder;

   @SpringBootApplication
   public class MyApplication extends SpringBootServletInitializer {

       public static void main(String[] args) {
           SpringApplication.run(MyApplication.class, args);  // still works 
for local dev with JAR
       }

       @Override
       protected SpringApplicationBuilder configure(SpringApplicationBuilder 
application) {
           return application.sources(MyApplication.class);
       }
   }
   ```

4. **Build the WAR**:

   ```
   mvn clean package
   ```

   → You'll get `target/your-app-1.0.0.war` (or similar)

5. **Deploy to Tomcat**:

   - Copy the `.war` file to Tomcat's `webapps/` directory
   - Start/restart Tomcat (`bin/startup.sh` or `.bat`)
   - Your app will be available at `http://localhost:8080/your-app-name/...` 
(context path = WAR filename unless renamed)

   Optional: Rename the WAR to `ROOT.war` → deploys at root context `/`

### Important Notes (2026 perspective)

- This method works perfectly with **Tomcat 9, 10, and 11** (Tomcat 10+ 
requires Jakarta EE migration if you're on older Spring Boot versions — use 
Spring Boot 3.x for full compatibility).
- Many large organizations still use this pattern for centralized ops, shared 
Tomcat clusters, or gradual migration from legacy Spring apps.
- For new greenfield projects, most teams prefer the **embedded server + 
Docker/Kubernetes** approach — it's simpler and more cloud-native.
- If you're hitting issues (e.g., 404s, class conflicts), check Tomcat logs 
(`logs/catalina.out`) — common culprits are missing 
`SpringBootServletInitializer` or duplicate Tomcat jars.

 

> camel-jbang - Add Tomcat as a runtime
> -------------------------------------
>
>                 Key: CAMEL-23080
>                 URL: https://issues.apache.org/jira/browse/CAMEL-23080
>             Project: Camel
>          Issue Type: New Feature
>          Components: camel-jbang
>            Reporter: Claus Ibsen
>            Priority: Major
>             Fix For: 4.x
>
>
> We can export to SB Q and main. But it would also be nice to export to 
> tomcat, which is essentially SB packaged as WAR and embedded on Tomcat. That 
> is a common practice to run many apps in the same JVM.
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to