2 Replies - 869 Views - Last Post: 03 June 2018 - 11:44 AM

#1 AsifSheikh   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 30-October 15

404 error in Spring Maven project

Posted 03 June 2018 - 02:16 AM

I am new to Spring and trying to develop one small application using spring annotation with Maven. But I am getting **"The requested resource is not available."**I can understand that server is not able to locate the requested resource. But I am not able to resolve it, So please help me on this.

Below are my project structure and code:-

SpringRootConfig.java
package com.capp.config;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.ComponentScan;
@Configurable
@ComponentScan( basePackages = {"com.capp"})
public class SpringRootConfig {[media]http://[/media]


}

    package com.capp.config;

    import org.springframework.beans.factory.annotation.Configurable;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.ComponentScan;
    import org.springframework.web.servlet.ViewResolver;
    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;

    @SuppressWarnings("deprecation")
    @Configurable
    @ComponentScan( basePackages = {"com.capp"})
    @EnableWebMvc
    public class SpringWebConfig extends WebMvcConfigurerAdapter {


        public void addResourceHandlers(ResourceHandlerRegistry registry) {


        }

        @Bean
        public ViewResolver viewResolver() {

            InternalResourceViewResolver vr =new InternalResourceViewResolver();
            vr.setViewClass(JstlView.class);
            vr.setPrefix("/WEB-INF/view/");
            vr.setSuffix(".jsp");
            return vr;
        }
    }
    ContactAppDispatcherServletIntializer.java
    package com.capp.config;

    import javax.servlet.ServletContext;
    import javax.servlet.ServletException;

    import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

    public class ContactAppDispatcherServletIntializer extends AbstractAnnotationConfigDispatcherServletInitializer {

        @Override
        protected Class<?>[] getRootConfigClasses() {
            return new Class[] {SpringRootConfig.class};
        }

        @Override
        protected Class<?>[] getServletConfigClasses() {
            // TODO Auto-generated method stub
            return new Class[] {SpringRootConfig.class};
        }

        @Override
        protected String[] getServletMappings() {
            // TODO Auto-generated method stub
            return new String[] {"/"};
        }

        @Override
        public void onstartup(ServletContext servletContext) throws ServletException {
            // TODO Auto-generated method stub
            super.onstartup(servletContext);
        }




    }
TestController.java    
package com.capp.controller;

    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    @Controller
    public class TestController {

        @RequestMapping(value="/test/hello")
        public String helloWorld() {

            return "hello";
        }

    }
C:\Users\Asif\Downloads\Projectst1.jpg

Is This A Good Question/Topic? 0
  • +

Replies To: 404 error in Spring Maven project

#2 AsifSheikh   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 30-October 15

Re: 404 error in Spring Maven project

Posted 03 June 2018 - 08:05 AM

Hi All, Able to find out the reason, My all jar files are available at the build path and not in the lib folder. So move all the jars to lib folder and it works fine.
Was This Post Helpful? 0
  • +
  • -

#3 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5358
  • View blog
  • Posts: 14,256
  • Joined: 18-April 07

Re: 404 error in Spring Maven project

Posted 03 June 2018 - 11:44 AM

Nice! :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1