Spring 4 REST Hibernate CRUD Example

In this tutorial, we will see the following CRUD operations on Employee entity using Spring 4 REST Services using Hibernate JPA. The following are REST samples for each operation.

  • Add Employee : http://localhost:8080/spring-rest-hibernate/rest/employee/add
  • Update Employee:http://localhost:8080/spring-rest-hibernate/rest/employee/update
  • Delete Employee: http://localhost:8080/spring-rest-hibernate/rest/employee/delete/16
  • List all employees : http://localhost:8080/spring-rest-hibernate/rest/employee/delete/all
  • Get Employee By ID : http://localhost:8080/spring-rest-hibernate/rest/employee/16 (16 is employeeID passing as path variable)

Installations:

  • Spring v.4
  • Tomcat
  • Hibernate v.5
  • MySQL
  • Maven 4

 

Spring 4 REST CRUD Examples

As shown in above diagram, We will create the classes

  1. Spring MVC Controller annotated with @RestController
  2. Data Transfer Objects : We will create EmployeeDTO to transfer data from REST controller to Services. We can also use JPA Entities directly as entities if it is not sensitive data. We can also see this example in this tutorial as well
  3. Service Layer : We will be creating spring service interfaces and classes that are annotated with @Service
  4. DAO Layer :  DAO layers is created using @Repository annotations which are  JPA EntityManagerFactory for database operations in which Hibernate act as JPA provider.

Maven Dependencies:   4

Add below dependencies for JSON to POJO conversion otherwise you will get 415 Unsupported media type in Spring 4 MVC error.

<dependency>
 <groupId>com.fasterxml.jackson.core</groupId>
 <artifactId>jackson-core</artifactId>
 <version>2.7.1</version>
 </dependency>
 <dependency>
 <groupId>com.fasterxml.jackson.core</groupId>
 <artifactId>jackson-databind</artifactId>
 <version>2.7.1</version>
 </dependency>
 <dependency>
 <groupId>com.fasterxml.jackson.core</groupId>
 <artifactId>jackson-annotations</artifactId>
 <version>2.7.1</version>
 </dependency>

Spring REST Hibernate CRUD Tutorial Steps:

Lets create the simple Maven Project and later we will update it will necessary dependencies

  1. Create a New Maven Project in Eclipse: File -> New -> Project -> Maven Project and select simple archetype and click on Next. you will get below window and give the Group Id and Artifact Id as belowSpring REST Hibernate CRUD Example
  2. Update maven with below dependencies
    1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>org.javasavvy.spring-rest-hibernate</groupId>
        <artifactId>spring-rest-hibernate</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <packaging>war</packaging>
           <properties>
            <spring.version>4.3.6.RELEASE</spring.version>
            <hibernate.version>5.0.5.Final</hibernate.version>
            <mysql.version>5.1.31</mysql.version>
            <joda-time.version>2.3</joda-time.version>
           <mail.version>1.4.1</mail.version>
            <log4j.version>1.2.17</log4j.version>
       </properties>
       <build>
          <finalName>spring-rest-hibernate</finalName>
          <directory>target</directory>
          <sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
          <outputDirectory>target/classes</outputDirectory>
       <pluginManagement>
          <plugins>
            <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-war-plugin</artifactId>
               <version>3.0.0</version>
               <configuration>
                  <packagingExcludes>WEB-INF/lib/*.jar</packagingExcludes>
                  <resources>
                     <resource>
                        <directory>${project.basedir}/src/main/resources</directory>
                       <filtering>false</filtering>
                   </resource>
                 </resources>
                <warName>spring-rest-hibernate</warName>
               <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
       </plugin>
       <plugin>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-compiler-plugin</artifactId>
            <version>3.2</version>
               <configuration>
                 <source>1.8</source>
                 <target>1.8</target>
              </configuration>
       </plugin>
       </plugins>
       </pluginManagement>
       </build>
       <dependencies>
           <dependency>
                 <groupId>org.springframework</groupId>
                 <artifactId>spring-context</artifactId>
                 <version>${spring.version}</version>
           </dependency>
          <dependency>
               <groupId>org.springframework</groupId>
               <artifactId>spring-core</artifactId>
                <version>${spring.version}</version>
          </dependency>
         <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
           <version>${spring.version}</version>
          </dependency>
         <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
         </dependency>
        <dependency>
           <groupId>org.springframework</groupId>
           <artifactId>spring-webmvc</artifactId>
           <version>${spring.version}</version>
         </dependency>
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-tx</artifactId>
          <version>${spring.version}</version>
       </dependency>
         <dependency>
           <groupId>org.springframework</groupId>
           <artifactId>spring-jdbc</artifactId>
           <version>${spring.version}</version>
        </dependency>
         <dependency>
           <groupId>org.springframework</groupId>
          <artifactId>spring-orm</artifactId>
          <version>${spring.version}</version>
         </dependency>
         <dependency>
           <groupId>javax.servlet</groupId><artifactId>jstl</artifactId>
           <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId><artifactId>javax.servlet-api</artifactId>
           <version>3.1.0</version>
         </dependency>
       <dependency>
          <groupId>javax.servlet.jsp</groupId>
          <artifactId>javax.servlet.jsp-api</artifactId>
          <version>2.3.1</version>
        </dependency>
        <dependency>
          <groupId>org.hibernate</groupId>
          <artifactId>hibernate-core</artifactId>
          <version>${hibernate.version}</version>
        </dependency>
         <dependency>
           <groupId>org.hibernate</groupId>
           <artifactId>hibernate-c3p0</artifactId>
          <version>${hibernate.version}</version>
        </dependency>
        <dependency>
          <groupId>org.hibernate</groupId>
          <artifactId>hibernate-entitymanager</artifactId>
           <version>${hibernate.version}</version>
         </dependency>
        <dependency>
          <groupId>javax.transaction</groupId>
          <artifactId>jta</artifactId>
          <version>1.1</version>
        </dependency>
       <!-- MySQL -->
        <dependency>
          <groupId>mysql</groupId>
          <artifactId>mysql-connector-java</artifactId>
         <version>${mysql.version}</version>
        </dependency>
        <dependency>
          <groupId>com.fasterxml.jackson.core</groupId>
          <artifactId>jackson-core</artifactId>
          <version>2.7.1</version>
         </dependency>
         <dependency>
           <groupId>com.fasterxml.jackson.core</groupId>
           <artifactId>jackson-databind</artifactId>
           <version>2.7.1</version>
        </dependency>
         <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>2.7.1</version>
         </dependency>
        <dependency>
          <groupId>log4j</groupId>
          <artifactId>log4j</artifactId>
          <version>${log4j.version}</version>
        </dependency>
       </dependencies>
      </project>
  3. Create the project structure as per the above diagramSpring REST hibernate tutorial
  4. You need to configure Spring Dispatcher Servlet for REST Services in web.xml. We will configure url-mapping as /rest/*  
    1.  <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
       xsi:schemaLocation="http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/javaee 
       http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/javaee/web-app_3_1.xsd" version="3.1"> 
       <welcome-file-list>
           <welcome-file>index.html</welcome-file>
           <welcome-file>index.jsp</welcome-file>
       </welcome-file-list>
       <listener> 
          <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
       </listener>
       <context-param>
            <param-name>contextConfigLocation</param-name>
           <param-value>classpath*:applicationContext-jdbc.xml</param-value>
       </context-param>
       <servlet>
         <servlet-name>spring-dispatcher</servlet-name>
         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
         <init-param>
             <param-name>contextConfigLocation</param-name>
             <param-value>/WEB-INF/config/mvcConfig.xml</param-value><!-- enable mvc annotations in this file -->
         </init-param>
         <load-on-startup>1</load-on-startup>
       </servlet>
        <servlet-mapping> <!-- this servlet will invoke for all request with /rest/* -->
           <servlet-name>spring-dispatcher</servlet-name>
          <url-pattern>/rest/*</url-pattern>
        </servlet-mapping>
       </web-app>
  5. Create mvcConfig.xml file and enable mvc annotations
    1. <?xml version="1.0" encoding="UTF-8"?>
      <beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
       xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-4.0.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">
       <context:annotation-config /> 
       <mvc:annotation-driven />
       <context:component-scan base-package="org.javasavvy.spring.rest.conroller" />
       <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
      </beans>
  6. Create Rest Controller:
    • Annotate Controllers with @RestController annotation and it combines @ResponseBody annotation
    • you can also use @Controller annotation, but in this case you need to use @ResponseBody annotation on each return type
    • @RestController
      @RequestMapping("/employee")
      public class EmployeeController {
       
       @Autowired(required=true)
       private EmployeeService employeeService;
      //empId is Path Variable and url is /rest/employee/id
       @GetMapping(value="/{empId}",produces={MediaType.APPLICATION_JSON_VALUE})
       public EmployeeDTO getEmployee(@PathVariable("empId") long empId){
       System.out.println("calling get Employee method");
       return employeeService.getEmployee(empId);
       
       }
       
       @RequestMapping(value="/add",method=RequestMethod.POST,consumes={MediaType.APPLICATION_JSON_VALUE},produces={MediaType.APPLICATION_JSON_VALUE})
       public EmployeeDTO addEmployee(@RequestBody EmployeeDTO emp){
       
       System.out.println("calling add employee method"+emp.getEmail());
       emp = employeeService.addEmployee(emp);
       return emp;
       }
       
       @RequestMapping(value="/update",method=RequestMethod.POST,consumes={MediaType.APPLICATION_JSON_VALUE},produces={MediaType.APPLICATION_JSON_VALUE})
       public EmployeeDTO updateEmployee(@RequestBody EmployeeDTO emp){
       
       if(emp.getEmpId()>0){
       emp = employeeService.addEmployee(emp);
       }else{
       //throw error here
       }
       return emp;
       }
       // for Get Requests, you can use short form as @GetMapping
       @GetMapping(value="/all",produces={MediaType.APPLICATION_JSON_VALUE})
       public List<EmployeeDTO> getAll(){
       return employeeService.getAllEmployees();
       
       }
        
       @GetMapping(value="/delete/{empId}",produces={MediaType.APPLICATION_JSON_VALUE})
       public StatusDTO deleteEmployee(@PathVariable("empId") long empId){
       
            employeeService.deleteEmployee(empId);
            StatusDTO status = new StatusDTO();
            status.setMessage("Employee Deleted Successfully");
            status.setStatus(200);
            return status;
        }
       
      }
  7. Create Database Layer:
    • Create applicationContext-jdbc.xml
      • <?xml version="1.0" encoding="UTF-8"?>
        <beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
         xmlns:aop="http://www.springframework.org/schema/aop" xmlns:p="http://www.springframework.org/schema/p"
         xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
         xsi:schemaLocation="http://www.springframework.org/schema/beans
         http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
         http://www.springframework.org/schema/context
         http://www.springframework.org/schema/context/spring-context-4.0.xsd
         http://www.springframework.org/schema/tx
         http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
         http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd
         http://www.springframework.org/schema/aop
         http://www.springframework.org/schema/aop/spring-aop-4.0.xsd">
         <context:annotation-config />
         <context:component-scan base-package="org.javasavvy.spring.services" />
         <context:component-scan base-package="org.javasavvy.spring.dao" />
         <tx:annotation-driven transaction-manager="transactionManager" />
        
         <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
         <property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
         <property name="url" value="jdbc:mysql://localhost:3306/javasavvy" />
         <property name="username" value="root" />
         <property name="password" value="root" />
         </bean>
         <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
         <property name="entityManagerFactory" ref="entityManagerFactory" />
         </bean>
         <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
         <property name="dataSource" ref="dataSource" />
         <property name="persistenceUnitName" value="spring-jpa-unit" />
         <property name="jpaVendorAdapter"> 
         <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
         </property>
         <property name="jpaProperties">
         <props>
         <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
         <prop key="hibernate.show_sql">true</prop>
         <prop key="hibernate.format_sql">false</prop>
         <prop key="hibernate.hbm2ddl.auto">update</prop>
         </props>
         </property>
         </bean>
        
         <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
        
        </beans>
    • create entities
      • package org.javasavvy.spring.entity;
        
        import javax.persistence.Entity;
        import javax.persistence.GeneratedValue;
        import javax.persistence.GenerationType;
        import javax.persistence.Id;
        import javax.persistence.Table;
        
        @Entity
        @Table(name="employee")
        public class Employee {
         
         @Id
         @GeneratedValue(strategy=GenerationType.AUTO)
         private long employeeId;
         
         private String email;
         private String firstName;
         private String lastName;
         private String designation;
         private String projectName;
         public long getEmployeeId() {
         return employeeId;
         }
         public void setEmployeeId(long employeeId) {
         this.employeeId = employeeId;
         }
         public String getEmail() {
         return email;
         }
         public void setEmail(String email) {
         this.email = email;
         }
         public String getFirstName() {
         return firstName;
         }
         public void setFirstName(String firstName) {
         this.firstName = firstName;
         }
         public String getLastName() {
         return lastName;
         }
         public void setLastName(String lastName) {
         this.lastName = lastName;
         }
         public String getDesignation() {
         return designation;
         }
         public void setDesignation(String designation) {
         this.designation = designation;
         }
         public String getProjectName() {
         return projectName;
         }
         public void setProjectName(String projectName) {
         this.projectName = projectName;
         }
         
         
        }
    • create persistence.xml file in src/resources/META-INF folder
      • <?xml version="1.0" encoding="UTF-8"?>
        <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
         <persistence-unit name="spring-jpa-unit">
         </persistence-unit>
        </persistence>
    • Create Employee DAO Interface
      • package org.javasavvy.spring.dao;
        import java.util.List;
        import org.javasavvy.spring.entity.Employee;
        
        public interface EmployeeDAO {
         public Employee addEmployee(Employee employee);
         public Employee updateEmployee(Employee employee);
         public void deleteEmployee(Employee employee);
         public Employee getEmployee(long empId);
         public List<Employee> getAllEmployees();
        }
    • Create EmployeeDAO Impl class
      • package org.javasavvy.spring.dao;
        import java.util.List;
        import javax.persistence.EntityManager;
        import javax.persistence.PersistenceContext;
        import org.javasavvy.spring.entity.Employee;
        import org.springframework.stereotype.Repository;
        import org.springframework.transaction.annotation.Transactional;
        
        @Repository("employeeDAO")
        @Transactional
        public class EmployeeDAOImpl implements EmployeeDAO {
        
         @PersistenceContext
         public EntityManager entityManager;
         
         @Transactional(readOnly=false)
         public Employee addEmployee(Employee employee) {
             entityManager.persist(employee);
             return employee;
         }
        
         @Transactional(readOnly=false)
         public Employee updateEmployee(Employee employee) {
             entityManager.merge(employee);
             return employee;
         }
        
         @Transactional(readOnly=false)
         public void deleteEmployee(Employee employee) {
             entityManager.remove(employee);
         }
        
         @Transactional(readOnly=true)
         public Employee getEmployee(long empId) {
            String sql = "select emp from Employee emp where emp.employeeId="+empId;
          try{
              return (Employee) entityManager.createQuery(sql).getSingleResult();
            }catch(Exception e){
          }
         return null;
         }
        
         @Transactional(readOnly=true)
         public List<Employee> getAllEmployees() {
             return entityManager.createQuery("select emp from Employee emp").getResultList();
         }
        
        }
  8. Create Service Layer
    • Create EmployeeService Interface:
      • package org.javasavvy.spring.services;
        import java.util.List;
        import org.javasavvy.spring.rest.dto.EmployeeDTO;
        
        public interface EmployeeService {
        
         public EmployeeDTO addEmployee(EmployeeDTO emp);
         public EmployeeDTO updateEmployee(EmployeeDTO emp);
         public void deleteEmployee(long empId);
         public EmployeeDTO getEmployee(long empId);
         public List<EmployeeDTO> getAllEmployees();
        }
    • Create EmployeeService Implementation:
      •  Employee Service methods takes EmployeeDTO objects and converts them to Entities. You can also use entities to share data between REST controller to Servies.
      • package org.javasavvy.spring.services;
        
        import java.util.ArrayList;
        import java.util.List;
        import org.javasavvy.spring.dao.EmployeeDAO;
        import org.javasavvy.spring.entity.Employee;
        import org.javasavvy.spring.rest.dto.EmployeeDTO;
        import org.springframework.beans.factory.annotation.Autowired;
        import org.springframework.stereotype.Service;
        import org.springframework.transaction.annotation.Transactional;
        
        @Service("employeeService")
        @Transactional
        public class EmployeeServiceImpl implements EmployeeService {
        
         @Autowired(required=true)
         private EmployeeDAO employeeDAO;
         
         public EmployeeDTO addEmployee(EmployeeDTO emp) {
            System.out.println("adding data in service"+emp.getDesignation());
            Employee employee = new Employee();
            employee.setDesignation(emp.getDesignation());
            employee.setEmail(emp.getEmail());
            employee.setFirstName(emp.getFirstName());
            employee.setLastName(emp.getLastName());
            employee.setProjectName(emp.getProjectName());
            employee = employeeDAO.addEmployee(employee);
             emp.setEmpId(employee.getEmployeeId());
          return emp;
         }
        
         public EmployeeDTO updateEmployee(EmployeeDTO emp) {
         
           Employee employee = new Employee();
           employee.setEmployeeId(emp.getEmpId());;
           employee.setDesignation(emp.getDesignation());
           employee.setEmail(emp.getEmail());
           employee.setFirstName(emp.getFirstName());
           employee.setLastName(emp.getLastName());
           employee.setProjectName(emp.getProjectName());
           employee = employeeDAO.updateEmployee(employee);
          return emp;
         }
        
         public void deleteEmployee(long empId) {
            Employee employee =employeeDAO.getEmployee(empId);
            employeeDAO.deleteEmployee(employee);
         }
        
         public EmployeeDTO getEmployee(long empId) {
         
            Employee emp =employeeDAO.getEmployee(empId);
            EmployeeDTO empDTO = new EmployeeDTO();
            empDTO.setDesignation(emp.getDesignation());
            empDTO.setEmail(emp.getEmail());
            empDTO.setFirstName(emp.getFirstName());
            empDTO.setLastName(emp.getLastName());
            empDTO.setProjectName(emp.getProjectName());
            empDTO.setEmpId(emp.getEmployeeId());
          return empDTO;
         }
        
         public List<EmployeeDTO> getAllEmployees() {
              // Here you need to transform entities to DTO. If you use entities this is not required.
            List<Employee> list = employeeDAO.getAllEmployees();
            List<EmployeeDTO> dtoList = new ArrayList<EmployeeDTO>();
            for(Employee emp:list){
               EmployeeDTO empDTO = new EmployeeDTO();
               empDTO.setDesignation(emp.getDesignation());
               empDTO.setEmail(emp.getEmail());
               empDTO.setFirstName(emp.getFirstName());
               empDTO.setLastName(emp.getLastName());
              empDTO.setProjectName(emp.getProjectName());
              empDTO.setEmpId(emp.getEmployeeId());
              dtoList.add(empDTO);
         }
         
         return dtoList ;
         }
        
        }
  9. Create DTO classes: Lets create DTO classes which acts as Value Objects from controllers to services
    • EmployeeDTO
      1. package org.javasavvy.spring.rest.dto;
        import java.io.Serializable;
        
        public class EmployeeDTO implements Serializable {
         private static final long serialVersionUID = 1L;
          private long empId;
         private String email;
         private String firstName;
         private String lastName;
         private String designation;
         private String projectName;
         public long getEmpId() {
         return empId;
         }
         public void setEmpId(long empId) {
         this.empId = empId;
         }
         public String getEmail() {
         return email;
         }
         public void setEmail(String email) {
         this.email = email;
         }
         public String getFirstName() {
         return firstName;
         }
         public void setFirstName(String firstName) {
         this.firstName = firstName;
         }
         public String getLastName() {
         return lastName;
         }
         public void setLastName(String lastName) {
         this.lastName = lastName;
         }
         public String getDesignation() {
         return designation;
         }
         public void setDesignation(String designation) {
         this.designation = designation;
         }
         public String getProjectName() {
         return projectName;
         }
         public void setProjectName(String projectName) {
         this.projectName = projectName;
         }
        
        }
    • Status DTO
      1. package org.javasavvy.spring.rest.dto;
        
        public class StatusDTO {
        
         private long status;
         private String message;
         public long getStatus() {
         return status;
         }
         public void setStatus(long status) {
         this.status = status;
         }
         public String getMessage() {
         return message;
         }
         public void setMessage(String message) {
         this.message = message;
         }
        
        }

        Now deploy the code and you can use the plugin chrome to test service

        Access the url with below data payload: http://localhost:8080/spring-rest-hibernate/rest/employee/add

        1.  {"empId":0,
           "email":"jayaram@gmail.com",
           "firstName":"jayaram",
           "lastName":"vijay",
           "designation":"test",
           "projectName":"test"}

          REST Tutorial

        2. http://localhost:8080/spring-rest-hibernate/rest/employee/allREST Tutorial

          Download Spring REST CRUD JPA Code

If you are getting 404 error then access below link to apply eclipse maven run time settings which are required to run maven application in your tomcat:

Tomcat Maven Deployment in Eclipse

Tomcat Maven Deployment in Eclipse You will get 404 error when you deploy the imported maven web application into tomcat. so first time you need to run the maven command toREAD MORE

8 Comments

  1. aba

    404 http status

    Reply
  2. joe

    same as aba, 404 not found, can we get a solution?

    Reply
  3. krs

    same… 404

    Reply
  4. Jayaram Pokuri (Post author)

    What is the URL you are trying to access?

    Reply
  5. Jayaram Pokuri (Post author)

    What is the URL you are trying to access?

    Reply
  6. d

    Any URL gives out 404

    Reply
  7. Jayaram Pokuri (Post author)

    I thought you guys are configured tomcat with maven in you local properly. Here access the below link that I explained other steps to run the application in tomcat.

    http://www.javasavvy.com/tomcat-maven-deployment-eclipse

    Now you wont get 404 error.

    Reply
  8. arun

    Hi, I am also getting 404 error . I have deployed war file in webapps folder.pls assist me .

    Reply

Leave a Comment

Your email address will not be published. Required fields are marked *