1

I am trying to build a spring project without the use of web.xml, but I am frequently getting this error, I've tried everything but so far nothing has solved the problem,

**Sep 15, 2015 11:36:50 AM org.springframework.web.servlet.PageNotFound noHandlerFound WARNING: No mapping found for HTTP request with URI [/TestApp/] in DispatcherServlet with name 'dispatcher'** 

here is my configuration:-

package com.springWeb.config; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.web.WebApplicationInitializer; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcher ServletInitializer; public class WebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer implements WebApplicationInitializer { @Override protected Class<?>[] getRootConfigClasses() { return new Class[] { AppConfig.class }; } @Override protected Class<?>[] getServletConfigClasses() { return null; } @Override protected String[] getServletMappings() { System.out.println("\n\n\n\n\n\n now deploying"); return new String[]{ "/" }; } } 

My AppConfig Class

package com.springWeb.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.view.InternalResourceViewResolver; import org.springframework.web.servlet.view.JstlView; @EnableWebMvc @Configuration @ComponentScan(basePackages = "com.springweb.controller.*") @Import({ SpringSecurityConfig.class }) public class AppConfig { @Bean public InternalResourceViewResolver viewResolver() { System.out.println("\n\n\nello hello hello"); InternalResourceViewResolver viewResolver = new InternalResourceViewResolver(); viewResolver.setViewClass(JstlView.class); viewResolver.setPrefix("/WEB-INF/pages/"); viewResolver.setSuffix(".jsp"); return viewResolver; } } 

And My controller

package com.springWeb.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @Controller public class TestController { @RequestMapping(value = { "/", "/welcome**" }, method = RequestMethod.GET) public String index() { System.out.println("test est test ets tstsd"); return "index2"; } } 
4
  • Which version of Spring and tomcat are you utilizing? Might help. Commented Sep 15, 2015 at 6:22
  • How is your app deployed? As root (i.e. /) or as /TestApp if it is the first then the error is correct as there is no mapping for /TestApp. Commented Sep 15, 2015 at 6:27
  • I am using 4.2.1.RELEASE of spring, and using org.apache.tomcat.maven:tomcat7-maven-plugin:run to deploy the application. Commented Sep 15, 2015 at 6:58
  • if I add a index.jsp in the webapp folder that page is accessible. Commented Sep 15, 2015 at 7:03

1 Answer 1

1

I suspect it's your @ComponentScan directive. Try changing it to

@ComponentScan({"com.springWeb.*"}) 

Looks like you maybe have a type-o with com.springweb in all lowercase.

Sign up to request clarification or add additional context in comments.

4 Comments

Tried that @ComponentScan(basePackages = "com.springweb.controller.*") and @ComponentScan(basePackages = "com.springweb.controller") no combination is working
Have you tried with the proper case? Your package is com.springWeb not com.springweb?
It was a stupid mistake after thanks for noticing that, had been banging my head for nothing
Haha I know that feeling! I had a hell of a time figuring all of this out on my first run. Good luck!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.