Spring REST调用没有返回我想要的页面

时间:2013-06-06 12:49:47

标签: spring rest spring-mvc

我正在进行示例Spring REST调用..我向控制器发送了一个URL,控制器应该返回一个页面..

我不认为它会进入控制器:

我的webconfig:

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = {"com.xxxx.mvc.web"})
public class WebMVCConfiguration extends WebMvcConfigurerAdapter
{

    private static final Logger logger = LoggerFactory.getLogger(WebMVCConfiguration.class);

    @Bean
    public ViewResolver resolver()
    {
        UrlBasedViewResolver url = new UrlBasedViewResolver();
        url.setPrefix("views/");
        url.setViewClass(JstlView.class);
        url.setSuffix(".jsp");
        return url;
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry)
    {
        logger.debug("setting up resource handlers");
        registry.addResourceHandler("/resources/").addResourceLocations("/resources/**");
    }

    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer)
    {
        logger.debug("configureDefaultServletHandling");
        configurer.enable();
    }

    @Bean
    public SimpleMappingExceptionResolver simpleMappingExceptionResolver()
    {
        SimpleMappingExceptionResolver b = new SimpleMappingExceptionResolver();

        Properties mappings = new Properties();
        mappings.put("org.springframework.web.servlet.PageNotFound", "p404");
        mappings.put("org.springframework.dao.DataAccessException", "dataAccessFailure");
        mappings.put("org.springframework.transaction.TransactionException", "dataAccessFailure");
        b.setExceptionMappings(mappings);
        return b;
    }
}

我的控制员:

@Controller
@RequestMapping("/ask")
class IndexController
{

    private static final Logger logger = LoggerFactory.getLogger(IndexController.class);


    @RequestMapping(value = "/{name}", method = RequestMethod.GET)
    public String getName(@PathVariable String name, ModelMap model)
    {

        logger.debug("I am in the controller and got user name: " + name);

        /*

            Taking the REST call param 'name' and setting it to the user
            attribute for the output screen

         */

        model.addAttribute("user", name);

        return "helloworld";

    }

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String getDisplayDefault(ModelMap model) {

        /*

            you did not enter a name so the default is going to run

         */


        model.addAttribute("user", "mouse");
        return "list";

    }
}

这是基本的,我不明白为什么我会收到以下错误:

HTTP状态404 - /springmvc-rest-test/ask/views/helloworld.jsp

message /springmvc-rest-test/ask/views/helloworld.jsp

description The requested resource is not available.

0 个答案:

没有答案