Deploy Spring MVC on Oracle WebLogic Server
1. The objective of the document
In the post, I will guide you how to deploy Spring MVC Web app on Oracle WebLogic Server. The post is written based on:
Spring MVC 4.x
Oracle WebLogic Server 12c (12.2.1.1.0).
Make sure that you have already installed WebLogic Server, if not, you can see the see the instructions here:
In the post, I will package Spring MVC Web app that is written on Eclipse and deploye on WebLogic Server.
Take note that if you deploy Spring MVC on other servers such as Tomcat and Glassfish, you do not need to change anything on your Source code. However if you deploy it on WebLogic, you need to add some configuration files to source code prior to package.
I will deploy the application "Hello World Spring MVC" on WebLogic. You can see the application here:
Or download Source Code:
2. Add the configuration to the project
This is the image of Project after completion:
Adding weblogic.xml to WEB-INF. In the weblogic.xml file, you need to configure contextPath (context-root) for application. In case I name it as /springmvc. You can name as / if you want to use empty ContextPath.
/WEB-INF/weblogic.xml
<?xml version='1.0' encoding='UTF-8'?>
<weblogic-web-app>
<context-root>/springmvc</context-root>
<container-descriptor>
<show-archived-real-path-enabled>true</show-archived-real-path-enabled>
</container-descriptor>
</weblogic-web-app>
3. Packaging Applications
Maven Clean:
Maven Install:
War file was created on the "target" folderof project.
4. Deploy on Weblogic
Note: If you get error in one of the deployment step, let's see the Appendix at the end of the post.
Your application has been deployed on WebLogic and it has the status "prepared". You need to take one more step to activate it.
Re-unlock to change.
Start apps:
Your application has been activated successfully.
Test apps:
6. Some errors when deploying
If you get error below during the deployment process on WebLogic:
java.io.FileNotFoundException:
Could not open ServletContext resource [/WEB-INF/SpringDispatcher-servlet.xml]
The cause of error found is that your project Spring MVC uses Annotation to configure (not use XML) but application still reads configuration from XML file (SpringDispatcher-servlet.xml) that is not existing on your Project.
You need to configure it on SpringWebAppInitializer to make sure that application will not find to read XML files above-mentioned.
You need to configure it on SpringWebAppInitializer to make sure that application will not find to read XML files above-mentioned.
// Add code:
dispatcher.setInitParameter("contextClass", appContext.getClass().getName());
servletContext.addListener(new ContextLoaderListener(appContext));
View full code:
SpringWebAppInitializer.java
package org.o7planning.hellospringmvc.config;
import javax.servlet.FilterRegistration;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.DispatcherServlet;
public class SpringWebAppInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext();
appContext.register(ApplicationContextConfig.class);
// Dispatcher Servlet
ServletRegistration.Dynamic dispatcher = servletContext.addServlet("SpringDispatcher",
new DispatcherServlet(appContext));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
// IMPORTANT!!
dispatcher.setInitParameter("contextClass", appContext.getClass().getName());
// IMPORTANT!!
servletContext.addListener(new ContextLoaderListener(appContext));
// UTF8 Charactor Filter.
FilterRegistration.Dynamic fr = servletContext.addFilter("encodingFilter", CharacterEncodingFilter.class);
fr.setInitParameter("encoding", "UTF-8");
fr.setInitParameter("forceEncoding", "true");
fr.addMappingForUrlPatterns(null, true, "/*");
}
// .........
}
Java Application Servers Tutorials
- Install Tomcat Server for Eclipse
- Install Tomcat Server
- Install Glassfish Web Server on Windows
- Install Oracle WebLogic Server
- How to create Windows Service for Oracle WebLogic Server?
- Deploy Spring Boot Application on Tomcat Server
- Deploy Spring Boot Application on Oracle WebLogic Server
- Deploy Spring MVC on Oracle WebLogic Server
- Install SSL Certificate for Tomcat Server
- Install a free SSL certificate Let's Encrypt for Tomcat Server on Ubuntu
Show More
Spring MVC Tutorials
- Spring Tutorial for Beginners
- Install Spring Tool Suite for Eclipse
- Spring MVC Tutorial for Beginners - Hello Spring 4 MVC
- Configure Static Resources in Spring MVC
- Spring MVC Interceptors Tutorial with Examples
- Create a Multiple Languages web application with Spring MVC
- Spring MVC File Upload Tutorial with Examples
- Simple Login Java Web Application using Spring MVC, Spring Security and Spring JDBC
- Spring MVC Security with Hibernate Tutorial with Examples
- Spring MVC Security and Spring JDBC Tutorial (XML Config)
- Social Login in Spring MVC with Spring Social Security
- Spring MVC and Velocity Tutorial with Examples
- Spring MVC and FreeMarker Tutorial with Examples
- Use Template in Spring MVC with Apache Tiles
- Spring MVC and Spring JDBC Transaction Tutorial with Examples
- Use Multiple DataSources in Spring MVC
- Spring MVC and Hibernate Transaction Tutorial with Examples
- Spring MVC Form Handling and Hibernate Tutorial with Examples
- Run background scheduled tasks in Spring
- Create a Java Shopping Cart Web Application using Spring MVC and Hibernate
- Simple CRUD example with Spring MVC RESTful Web Service
- Deploy Spring MVC on Oracle WebLogic Server
Show More