DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Deploy Spring Boot Apps From Jar to War
  • A Practical Guide to Creating a Spring Modulith Project
  • Distributed Tracing System (Spring Cloud Sleuth + OpenZipkin)
  • Java, Spring Boot, and MongoDB: Performance Analysis and Improvements

Trending

  • MySQL to PostgreSQL Database Migration: A Practical Case Study
  • Understanding and Mitigating IP Spoofing Attacks
  • Enhancing Security With ZTNA in Hybrid and Multi-Cloud Deployments
  • A Simple, Convenience Package for the Azure Cosmos DB Go SDK
  1. DZone
  2. Coding
  3. Frameworks
  4. Creating Spring Boot Application for WebLogic and Tomcat

Creating Spring Boot Application for WebLogic and Tomcat

We look at some of the most popular frameworks for spinning up applications and servers. Read on to get started!

By 
Anish Panthi user avatar
Anish Panthi
·
Dec. 19, 18 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
61.6K Views

Join the DZone community and get the full member experience.

Join For Free

In this post, we are going to create our first Spring Boot Application. Since Tomcat is an embedded container that comes with Spring Boot applications, it is easy to deploy in Tomcat containers, but, today, we will deploy our first Spring Boot Application in Oracle’s WebLogic server. We will use Spring Boot 1.x here. I will create another post on how to deploy Spring Boot 2.x in WebLogic 12.1.2.1

If you are new to WebLogic server, please download the latest version of WebLogic server first from here. I’m not going to discuss the installation process of WebLogic. Please follow Oracle’s documentation on how to install and configure WebLogic in your local system.

Let's start deploying our first Spring Boot Application in WebLogic. But, before that, let's create one sample application in Spring Boot. There are various ways of creating applications for Spring Boot. I recommend you start from here. For this project, I will walk you through creating an application for Spring Boot, step-by-step. Please use the following details while creating your own project:

Download this project and import it to your best IDE. I’ll be using the IntelliJ IDE for this tutorial.

After importing this project to your IDE, you will see two classes under your root package:

  1. BootUserManagementApi.java (Main Spring Boot Application)

  2. ServletInitializer.java

To deploy your app in WebLogic, you need to edit you ServletInitializer.java. Update this class as follows:

public class ServletInitializer extends SpringBootServletInitializer implements WebApplicationInitializer {
   @Override   
   protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
      return application.sources(BootUserMgmtApplication.class);   }
}

To deploy your application in WebLogic you need to implement WebApplicationInitializer in your ServletInitializer, which is the extra effort you need to perform. Remember, we need to add this interface if you are going to deploy in WebLogic server. For Tomcat, its not necessary.

Next, you need to add a weblogic.xml file in your project to tell the WebLogic Server to load this file while deploying you app. You need to add this file into ../src/main/web-app/WEB-INF folder. You need to create a folder for this. Code for weblogic.xml is as follows:

Please note that we just need to include "org.slf4j.*", the rest can be excluded.

Now, create one package under your main package and name it “controller” and add one class for the controller. I’m going to name this class HomeController, which is going to be a RestController for this project. Finally, your project structure should be like this:

application.properties

That’s it. You can now run your application. Go to http://localhost:8080/app/usermanagement/api/v1/home

You should see: Hello World

Remember, one more thing, if you are going to deploy your app in WebLogic then you need to exclude Tomcat from Gradle or Maven. Below is my build.gradle script:

buildscript {
   ext {
      springBootVersion = '1.5.9.RELEASE'   
   }
   repositories {
      mavenCentral()
   }
   dependencies {
      classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
      classpath("javax.servlet:javax.servlet-api:4.0.0")
   }
}

apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'org.springframework.boot'
apply plugin: 'war'

group = 'user-management'
version = '1'
sourceCompatibility = 1.8

repositories {
   mavenCentral()
}

configurations {
   providedRuntime
}

dependencies {
   compile('org.springframework.boot:spring-boot-starter-web')
         {
            exclude module: "spring-boot-starter-tomcat"         
         }
   runtime('org.springframework.boot:spring-boot-devtools')
   compileOnly('org.projectlombok:lombok')
   testCompile('org.springframework.boot:spring-boot-starter-test')

   providedCompile 'javax.servlet:javax.servlet-api:4.0.0'
}

If you want to deploy your app in Tomcat, then use the following build.gradle:

buildscript {
   ext {
      springBootVersion = '1.5.9.RELEASE'   
   }
   repositories {
      mavenCentral()
   }
   dependencies {
      classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
//    classpath("javax.servlet:javax.servlet-api:4.0.0")   
   }
}

apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'org.springframework.boot'
apply plugin: 'war'

group = 'user-management'
version = '1'
sourceCompatibility = 1.8

repositories {
   mavenCentral()
}

configurations {
   providedRuntime
}

dependencies {
   compile('org.springframework.boot:spring-boot-starter-web')
//       {          
//              exclude module: "spring-boot-starter-tomcat"       
//       }   
   runtime('org.springframework.boot:spring-boot-devtools')
   compileOnly('org.projectlombok:lombok')
   testCompile('org.springframework.boot:spring-boot-starter-test')

// providedCompile 'javax.servlet:javax.servlet-api:4.0.0'
}

That’s all you need to do. If you have any questions or issues, please feel free to comment. I will help to fix your issues.

The complete project is available in GitHub.

Spring Framework Spring Boot application Apache Tomcat

Published at DZone with permission of Anish Panthi. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Deploy Spring Boot Apps From Jar to War
  • A Practical Guide to Creating a Spring Modulith Project
  • Distributed Tracing System (Spring Cloud Sleuth + OpenZipkin)
  • Java, Spring Boot, and MongoDB: Performance Analysis and Improvements

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!