--- title: "Spring MVC" url: https://docs.catalyst.zoho.com/en/serverless/help/appsail/help-guides/java/spring-mvc/ description: "Catalyst AppSail is a fully-managed PaaS component of Catalyst Serverless that enables you to develop and deploy services in Java, Node.js, and Python in the cloud with ease, and manage your platform instances." last_updated: 2025-11-03T10:48:29Z service: Serverless type: general --- # Spring- MVC The [Spring Web MVC](https://docs.spring.io/spring-framework/docs/3.2.x/spring-framework-reference/html/mvc.html) framework is a module of the popular [Spring framework](https://spring.io) that follows a Model-View-Controller architecture. This framework allows for the creation of web applications, incorporating the advantages of the Spring framework along with loose coupling of components in the MVC design pattern. It is built around a `DispatcherServlet` that handles HTTP requests and responses, and dispatches the requests to necessary handlers and controllers. This example explains the steps to build a sample app in the Spring MVC framework, export it as a WAR file, and deploy it to AppSail. 1. Create a new Maven project using an IDE of your choice. You must select the following [Archetype](https://maven.apache.org/guides/introduction/introduction-to-archetypes.html) for the project: `org.apache.maven.archetypes maven-archetype-webapp`. 2. In the `pom.xml` file of your project, add the spring dependencies given below. ```java <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>5.2.19.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>5.2.19.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <version>5.2.19.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>5.2.19.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>5.2.19.RELEASE</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> ``` 3. Add the dependencies below in a build enclosure to compile and generate the WAR file. ```java <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.0</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <plugin> <artifactId>maven-war-plugin</artifactId> <version>3.2.1</version> <configuration> <warSourceDirectory>WebContent</warSourceDirectory> </configuration> </plugin> </plugins> ``` 4. Create a [Spring XML configuration file](https://docs.spring.io/spring-framework/docs/4.2.x/spring-framework-reference/html/xsd-configuration.html) in your project, and add the bean configurations given below. ```java <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd "> ``` Your Spring configuration file should look something like this: ```java <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd "> <mvc:annotation-driven/> <mvc:default-servlet-handler/> <context:component-scan base-package="com.amelia.example.controller" /> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/"></property> <property name="suffix" value=".jsp"></property> </bean> </beans> ``` 5. Add a server runtime to the project. For example, if you are working in the Eclipse IDE, you can add a targeted runtime for the Apache Tomcat server in the following way: Right click on the **project -> Properties -> Targeted Runtime**. Here, you can add the required runtime, then click **Apply**. 6. You can now add the required controller and error page handling, as well as a servlet mapping in the `web.xml` file of your project. For example, you can use the configuration given below: ```java <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <servlet> <servlet-name>helloworld</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>helloworld</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <error-page> <error-code>404</error-code> <location>/error.jsp</location> </error-page> <error-page> <error-code>401</error-code> <location>/error.jsp</location> </error-page> <error-page> <error-code>500</error-code> <location>/error.jsp</location> </error-page> <error-page> <error-code>400</error-code> <location>/error.jsp</location> </error-page> <error-page> <error-code>403</error-code> <location>/error.jsp</location> </error-page> <error-page> <error-code>408</error-code> <location>/error.jsp</location> </error-page> <error-page> <error-code>413</error-code> <location>/error.jsp</location> </error-page> <error-page> <error-code>414</error-code> <location>/error.jsp</location> </error-page> <error-page> <error-code>505</error-code> <location>/error.jsp</location> </error-page> <error-page> <error-code>405</error-code> <location>/error.jsp</location> </error-page> <error-page> <error-code>409</error-code> <location>/error.jsp</location> </error-page> <error-page> <exception-type> java.lang.Throwable </exception-type> <location>/error.jsp</location> </error-page> ``` 7. You can upload the application to Catalyst by exporting it as a WAR file. In the Eclipse example, you can right click on the project and choose **Export As -> WAR**. You must do the following: a. Choose a destination with file name as `ROOT.war` b. Uncheck the Optimize for specific server runtime option. 8. You can now [initialize an AppSail service](https://docs.catalyst.zoho.com/en/cli/v1/initialize-resources/initialize-appsail/) in the same directory from the CLI or [add it](https://docs.catalyst.zoho.com/en/cli/v1/add-appsail/) in an existing project directory. The app's source must be your application's directory. Provide the following values while initializing the app service: **Stack:** Java 8 **Platform:** Java WAR 9. Ensure the compiled files are added in the build directory you specify during initialization. Catalyst will automatically ZIP your app files during deployment to the remote console. 10. [Deploy the app service](https://docs.catalyst.zoho.com/en/cli/v1/deploy-resources/deploy-appsail//) to the console. Access the deployed app service from its [endpoint URL](https://docs.catalyst.zoho.com/en/serverless/help/appsail/key-concepts/appsail-execution/#custom-domain-url).