Skip to content

Instantly share code, notes, and snippets.

@dhruvilp
Created March 25, 2025 03:49
Show Gist options
  • Save dhruvilp/b3601e82e6d3bcb16ce0125510dff906 to your computer and use it in GitHub Desktop.
Save dhruvilp/b3601e82e6d3bcb16ce0125510dff906 to your computer and use it in GitHub Desktop.
Tomcat to Spring Boot
nference Providers
NEW
Fireworks
Text Generation
Reset
Examples
Input a message to start chatting with deepseek-ai/DeepSeek-V3-0324.
How can I convert an app running on tomcat Catalina 8 server to spring boot app with jdk 17
Converting a Tomcat 8 Application to Spring Boot with JDK 17
Converting a traditional Tomcat 8 web application to a Spring Boot application with JDK 17 involves several steps. Here's a comprehensive guide:
Prerequisites
JDK 17 installed
Basic understanding of Spring Boot
Existing WAR file or source code of your Tomcat 8 application
Step-by-Step Conversion Process
1. Set up a new Spring Boot project
bash
Copy
# Use Spring Initializr (https://start.spring.io/) to create a new project with:
- Java 17
- Spring Boot 3.x (compatible with JDK 17)
- Packaging: JAR (preferred) or WAR if needed
- Add required dependencies (Web, JPA, etc.)
2. Migrate application structure
Move your Java source files to src/main/java
Move web resources to src/main/resources/static
Move JSP files (if any) to src/main/webapp/WEB-INF (requires WAR packaging)
Move configuration files to src/main/resources
3. Update dependencies
Modernize your dependencies in pom.xml or build.gradle:
xml
Copy
<!-- Example pom.xml updates -->
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<!-- Spring Boot Starter Web for Servlet support -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Include any Tomcat-specific dependencies if needed -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope> <!-- Only if building WAR -->
</dependency>
</dependencies>
4. Convert web.xml to Spring Boot configuration
If using web.xml:
Convert servlets and filters to Spring Beans
Replace servlet mappings with @Controller or @RestController
Replace context parameters with application.properties/yml
5. Migrate application configuration
Replace context.xml with:
application.properties or application.yml
Spring @Configuration classes
Environment variables
6. Update database connection
If using JDBC:
properties
Copy
# application.properties example
spring.datasource.url=jdbc:mysql://localhost:3306/yourdb
spring.datasource.username=dbuser
spring.datasource.password=dbpass
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
7. Handle JSP (if applicable)
Add required dependencies:
xml
Copy
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
Configure view resolver in a @Configuration class:
java
Copy
@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/views/");
resolver.setSuffix(".jsp");
return resolver;
}
8. Replace legacy components
Replace legacy persistence (Hibernate XML mappings) with Spring Data JPA
Replace EJBs with Spring @Service or @Repository
Replace custom security with Spring Security
9. Update static resources handling
Spring Boot serves static content from:
/static
/public
/resources
/META-INF/resources
10. Test and run
bash
Copy
# Run as standalone Spring Boot app
mvn spring-boot:run
# Or build and run the JAR
mvn clean package
java -jar target/yourapp-0.0.1-SNAPSHOT.jar
Common Challenges
Dependency conflicts: Careful version management needed
Servlet API differences: Spring Boot 3.x uses Servlet 6.0
JNDI resources: Configure via application.properties or programmatically
Legacy XML configurations: Convert to Java-based configuration
Removal of outdated APIs: Some APIs available in JDK 8 may be removed in JDK 17
Additional Considerations
For container deployment, consider using Spring Boot's embedded Tomcat (default)
If you must deploy to an external Tomcat, use WAR packaging
Review all libraries for JDK 17 compatibility
Update any Java code using deprecated APIs removed in JDK 17
Would you like me to elaborate on any specific part of this conversion process?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment