java - Spring MVC annotation based configuration not working -


i tried create simple spring mvc project of this tutorial when deployed showing 404 server error.since beginner spring mvc couldn't make out wrong in project inspite of going through answers here , other places well.i appreciate in figuring out.

these contents:

  • pom.xml

    <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/maven-v4_0_0.xsd">     <modelversion>4.0.0</modelversion>     <groupid>com</groupid>     <artifactid>deevigeweb</artifactid>     <packaging>war</packaging>     <version>0.0.1-snapshot</version>     <name>deevigeweb maven webapp</name>     <url>http://maven.apache.org</url>     <dependencies>         <dependency>             <groupid>junit</groupid>             <artifactid>junit</artifactid>             <version>3.8.1</version>             <scope>test</scope>         </dependency>          <dependency>             <groupid>javax.servlet</groupid>             <artifactid>javax.servlet-api</artifactid>             <version>3.1.0</version>         </dependency>          <dependency>             <groupid>org.springframework</groupid>             <artifactid>spring-core</artifactid>             <version>4.1.6.release</version>         </dependency>          <dependency>             <groupid>org.springframework</groupid>             <artifactid>spring-context</artifactid>             <version>4.1.6.release</version>         </dependency>         <dependency>            <groupid>org.springframework</groupid>            <artifactid>spring-webmvc</artifactid>            <version>4.1.6.release</version>        </dependency>        <dependency>           <groupid>javax.servlet</groupid>           <artifactid>jstl</artifactid>           <version>1.2</version>       </dependency>     </dependencies>    <build>       <finalname>deevigeweb</finalname>    </build> </project> 
  • servlet initializer(deevigeservletinitializer.java)

    package com.deevigeweb.config; import org.springframework.web.servlet.support.abstractannotationconfigdispatcherservletinitializer;  public class deevigeservletinitializer extends abstractannotationconfigdispatcherservletinitializer {      @override     protected class<?>[] getrootconfigclasses() {        return new class[] {deevigewebmvcconfig.class};     }      @override     protected class<?>[] getservletconfigclasses() {        return null;     }      @override     protected string[] getservletmappings() {        return new string[] {"/"};     }  } 
  • web mvc config(deevigewebmvcconfig.java)

    package com.deevigeweb.config;  import org.springframework.context.annotation.bean; import org.springframework.context.annotation.componentscan; import org.springframework.context.annotation.configuration; import org.springframework.web.servlet.config.annotation.enablewebmvc; import org.springframework.web.servlet.config.annotation.resourcehandlerregistry; import org.springframework.web.servlet.config.annotation.webmvcconfigureradapter; import org.springframework.web.servlet.view.internalresourceviewresolver; import org.springframework.web.servlet.view.jstlview;  @enablewebmvc @configuration @componentscan({"com.deevigeweb"}) public class deevigewebmvcconfig extends webmvcconfigureradapter {     @override     public void addresourcehandlers(resourcehandlerregistry registry) {          registry.addresourcehandler("/resources/**").addresourcelocations("/resources/"); }  @bean public internalresourceviewresolver viewresolver(){     internalresourceviewresolver resolver = new internalresourceviewresolver();     resolver.setviewclass(jstlview.class);     resolver.setprefix("/web-inf/views");     resolver.setsuffix(".jsp");     return resolver; }  } 
  • controller(searchviewcontroller.java)

    package com.deevigeweb.controllers.webapp;  import org.springframework.web.bind.annotation.requestmapping; import org.springframework.web.bind.annotation.requestmethod; import org.springframework.web.servlet.modelandview;  public class searchviewcontroller {     @requestmapping(value="/",method=requestmethod.get)     public modelandview dolanding(){         return new modelandview("searchview");     } } 
  • jsp(searchview.jsp)

    <%@ page language="java" contenttype="text/html; charset=iso-8859-1" pageencoding="iso-8859-1"%> <!doctype html > <html>     <head>         <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">         <title>welcome</title>     </head>     <body>         <h1>welcome</h1>     </body> </html> 
  • directory structure project structure

maybe adding trailing slash trick you:

resolver.setprefix("/web-inf/views/"); 

also add @controller annotation on searchviewcontroller class


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -