Results 1 to 10 of 19

Thread: Spring 3.1 with No XML Not working

Threaded View

  1. #1
    Join Date
    Feb 2012
    Posts
    9

    Default Spring 3.1 with No XML Not working

    So I've setup a spring mvc 3.1 project from scratch and am not using any xml. Thing is my controllers are not getting registered. There are no errors what so ever its like the controller doesn't exist.

    The index page loads when I run the application but when I try the url thats mapped nothing happens.
    The console shows no errors and I have no build errors.

    My Initializer class looks like this:

    Code:
    @Configuration
    public class Initializer implements WebApplicationInitializer
    {
    public void onStartup(ServletContext container) throws ServletException
    	{
    		logger.info("Loading..");
    		System.out.print("YALLO");
    		AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    		rootContext.register(AppConfig.class);
    		
     
    		// Manage the lifecycle of the root application context
    		container.addListener(new ContextLoaderListener(rootContext));
     
    		// Create the dispatcher servlet's Spring application context
    		AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext();
    		dispatcherContext.register(DispatcherConfig.class);
     
    		// Register and map the dispatcher servlet
    		ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(dispatcherContext));
    		dispatcher.setLoadOnStartup(1);
    		dispatcher.addMapping("/"); 
    	}
    }

    My configuration class looks like this:
    Code:
    @Configuration
    @ComponentScan(basePackages = "com.yardy.controllers")
    public class DispatcherConfig
    {
    	private static final Logger logger = LoggerFactory.getLogger(DispatcherConfig.class);
    	
    	@Bean
    	public InternalResourceViewResolver configureInternalResourceViewResolver()
    	{
    		logger.error("HELLO");
    		InternalResourceViewResolver resolver = new InternalResourceViewResolver();
    		resolver.setPrefix("/WEB-INF/views/");
    		resolver.setSuffix(".jsp");
    		return resolver;
    	}
    }
    Controller looks like this:


    Code:
    package com.yardy.controllers;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    
    @Controller
    public class YardyController
    {
    	 private static final Logger logger = LoggerFactory.getLogger(YardyController.class);
    	 
    	 @RequestMapping(value = "/yardy")
    	 public String yardy()
    	 {
    		 System.out.print("Testing..");
    		logger.info("Welcome home!");
    		System.out.print("YARDY");
    		return "yardy";
    	 }
    }

    /yardy just 404's thou.

    Can anyone give me any insight into this.
    Perhaps point out something I'm missing.
    Last edited by loki70x7; Feb 6th, 2012 at 06:50 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •