spring java configuration issue: Rejected bean name 'requestMappingHandlerMapping': no URL paths identified

10,008

This is not the root cause @ravi, but I do see a few issues that I wanted to highlight to start with:

a. You seem to be loading up the Spring Java Config file twice, through the ContextLoaderListener and the Dispatcher servlet, do it only through the ContextLoaderListener, you can define your DispatcherServlet this way - to just load up an empty context(ideally have two java configs - one for the core application and one for the web configuration):

ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new GenericWebApplicationContext());
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");

b. Can you enable debug mode with log4j and see what else is logged - if that is not sufficient information, log at trace level.

c. Internal View Resolver path looks a little wrong - you are missing the forward "/":

resolver.setPrefix("/WEB-INF/jsp/");

Can you please try these and see what you see now.

Share:
10,008
javaMan
Author by

javaMan

I am a java developer. I have experience with java based spring configurations. I love front end. I play with jquery, javascript, html 5. i love creating web apps.

Updated on June 25, 2022

Comments

  • javaMan
    javaMan almost 2 years

    I am using spring java configs to create a web app.

    When I run on tomcat it says the resource /myapp/myapp not found

    In the console output i noticed the following. I am not sure whether this is causing any issue.

    I am showing only those log lines which look odd. as the log is so big

    INFO: validateJarFile(C:\libraries\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\myapp\WEB-INF\lib\javax.servlet-api-3.0.1.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
    
    
    Creating instance of bean 'beanNameHandlerMapping'
    Returning cached instance of singleton bean 'delegatingWebMvcConfiguration'
    Eagerly caching bean 'beanNameHandlerMapping' to allow for resolving potential circular     references
    Looking for URL mappings in application context: Root WebApplicationContext: startup date [Mon J     un 04 13:28:33 EDT 2012]; root of context hierarchy
    Rejected bean name  'org.springframework.context.annotation.internalConfigurationAnnotationProcessor': no URL paths identified
    Rejected bean name 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor': no URL paths identified
    Rejected bean name 'org.springframework.context.annotation.internalRequiredAnnotationProcessor': no URL paths identified
    Rejected bean name 'org.springframework.context.annotation.internalCommonAnnotationProcessor': no URL paths identified
    Rejected bean name 'webAppContextConfig': no URL paths identified
    Rejected bean name 'org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0': no URL paths identified
    Rejected bean name 'delegatingWebMvcConfiguration': no URL paths identified
    Rejected bean name 'requestMappingHandlerMapping': no URL paths identified
    Rejected bean name 'viewControllerHandlerMapping': no URL paths identified
    Rejected bean name 'beanNameHandlerMapping': no URL paths identified
    Rejected bean name 'resourceHandlerMapping': no URL paths identified
    Rejected bean name 'defaultServletHandlerMapping': no URL paths identified
    Rejected bean name 'requestMappingHandlerAdapter': no URL paths identified
    Rejected bean name 'mvcConversionService': no URL paths identified
    Rejected bean name 'mvcValidator': no URL paths identified
    Rejected bean name 'httpRequestHandlerAdapter': no URL paths identified
    Rejected bean name 'simpleControllerHandlerAdapter': no URL paths identified
    Rejected bean name 'handlerExceptionResolver': no URL paths identified
    Rejected bean name 'configureInternalResourceViewResolver': no URL paths identified
    Rejected bean name 'environment': no URL paths identified
    Rejected bean name 'systemProperties': no URL paths identified
    Rejected bean name 'systemEnvironment': no URL paths identified
    Rejected bean name 'servletContext': no URL paths identified
    Rejected bean name 'contextParameters': no URL paths identified
    Rejected bean name 'contextAttributes': no URL paths identified
    Rejected bean name 'importRegistry': no URL paths identified
    Rejected bean name 'messageSource': no URL paths identified
    Rejected bean name 'applicationEventMulticaster': no URL paths identified
    Finished creating instance of bean 'beanNameHandlerMapping'
    Creating shared instance of singleton bean 'resourceHandlerMapping'
    Creating instance of bean 'resourceHandlerMapping'
    Returning cached instance of singleton bean 'delegatingWebMvcConfiguration'
    Eagerly caching bean 'resourceHandlerMapping' to allow for resolving potential circular references
    Mapped URL path [/css/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
    Mapped URL path [/scripts/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
    Mapped URL path [/images/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
    Finished creating instance of bean 'resourceHandlerMapping'
    

    Here is the WebAppContextConfig.java

    package com.example;
    
    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;
    
    @Configuration
    @EnableWebMvc
    @ComponentScan(basePackages = "com.example")
    public class WebAppContextConfig extends WebMvcConfigurerAdapter{
    //Resolve logical view names to .jsp resources in /WEB-INF/views directory
    
    @Bean
    public InternalResourceViewResolver configureInternalResourceViewResolver() {
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("WEB-INF/jsp/");
        resolver.setSuffix(".jsp");
        return resolver;
    }
    
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/scripts/**").addResourceLocations("/scripts/");
        registry.addResourceHandler("/css/**").addResourceLocations("/css/");
        registry.addResourceHandler("/images/**").addResourceLocations("/images/");
    }
    }
    

    Here is the WebAppInitializer.java

     package com.example;
    
     import javax.servlet.ServletContext;
     import javax.servlet.ServletException;
     import javax.servlet.ServletRegistration;
    
     import org.springframework.context.annotation.ComponentScan;
     import org.springframework.web.WebApplicationInitializer;
     import org.springframework.web.context.ContextLoaderListener;
     import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
     import org.springframework.web.servlet.DispatcherServlet;
     import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
    
     public class WebAppInitializer implements WebApplicationInitializer {
    
    /* (non-Javadoc)
     * @see org.springframework.web.WebApplicationInitializer#onStartup(javax.servlet.ServletContext)
     */
    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
        rootContext.register(WebAppContextConfig.class);
        servletContext.addListener(new ContextLoaderListener(rootContext));
    
          AnnotationConfigWebApplicationContext dispatcherContext = 
                    new AnnotationConfigWebApplicationContext();
                  dispatcherContext.register(WebAppContextConfig.class);
    
        ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(rootContext));
        dispatcher.setLoadOnStartup(1);
        dispatcher.addMapping("/");
    
    
        DefaultServletHandlerConfigurer defaultConfig = new DefaultServletHandlerConfigurer(servletContext);
        defaultConfig.enable();
    
    }
    
    }
    

    Also is there any good place to look for java based spring mvc configuration?

    Thanks