Spring 3.1.1。发布。 RequestMappingHandlerMapping Autowired问题

时间:2014-05-26 15:18:46

标签: spring autowired wadl

我正在尝试向我的Spring Web Service应用程序添加WADL方法。我正按照此处主题的多个页面/帖子以及网络上的其他帮助网站的说明进行操作。

但是,我的应用程序一直在RequestMappingHandlerMapping的自动线上失败。

错误是:

Error creating bean with name 'wadlController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping net.my.app.ws.thing.WadlController.handlerMapping; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

我已经做了我能想到的一切,甚至还搜索了一下:

mvc:annotation-driven

但该应用程序已经完全是注释驱动器,所以这似乎不对。

我还能错过什么?这是Spring 3.1.1的问题吗?

1 个答案:

答案 0 :(得分:0)

以下是我的控制器顶部的代码。我确实通过自动连接ApplicationContext来实现它。但是,我并不喜欢这个解决方案。

package net.stuff.stuff.stuff;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.xml.namespace.QName;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.mvc.condition.ProducesRequestCondition;
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;


import net.stuff.wadl.*;

@Controller
@RequestMapping("/application.wadl")
public class WadlController  {
    private static final Logger log = Logger.getLogger(WadlController.class);

    @Autowired
    private ApplicationContext ctx;

    @RequestMapping(method = RequestMethod.GET, produces = { "application/xml" })
    public @ResponseBody WadlApplication generateWadl(HttpServletRequest request) {

        RequestMappingHandlerMapping handlerMapping = ctx.getBean(RequestMappingHandlerMapping.class);

        WadlApplication result = new WadlApplication();
        WadlDoc doc = new WadlDoc();
        doc.setTitle("REST Service WADL");
        result.getDoc().add(doc);
        WadlResources wadResources = new WadlResources();
        wadResources.setBase(getBaseUrl(request));

        if (handlerMapping == null) {
            log.error("handlerMapping is null in WadlController???");
            return null;
        }