spring MVC3错误无法实例化bean类[java.util.List]:指定的类是偶尔的接口

时间:2012-10-13 15:13:35

标签: java spring

我使用的是Spring MVC3,我找到了如下代码:

@Controller
class IndexController
{
    @ModelAttribute("allTags")
    public List<ArticleTag> allTags()
    {
        return Collections.emptyList();
    }
}

有时会出现错误消息

(并非总是)

SEVERE: Servlet.service() for servlet [appServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [java.util.List]: Specified class is an interface] with root cause
org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [java.util.List]: Specified class is an interface
        at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:101)
        at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.createAttribute(ModelAttributeMethodProcessor.java:132)
        at org.springframework.web.servlet.mvc.method.annotation.ServletModelAttributeMethodProcessor.createAttribute(ServletModelAttributeMethodProcessor.java:81)
        at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.resolveArgument(ModelAttributeMethodProcessor.java:103)
        at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:75)
        at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:156)
        at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:117)
        at org.springframework.web.method.annotation.ModelFactory.invokeModelAttributeMethods(ModelFactory.java:123)
        at org.springframework.web.method.annotation.ModelFactory.initModel(ModelFactory.java:97)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:614)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
        at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
        at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)

有人说,List是一个接口,plz使用ArrayList或LinkedList而不是

但是,我的问题是,为什么上面的代码并不总是错误?

当出现上述错误时,无论如何刷新页面,错误仍在继续,一切都消失了!但是,如果你重新启动tomcat,你有很好的机会来解决这个错误!如果没有上面发生的错误,它永远不会发生util下一个tomcat重启!

与类型为int或Integer的@ModelAttribute相同,很可能会出错,但在某些主机上,它永远不会发生

1 个答案:

答案 0 :(得分:-1)

更改以下代码

public ArticleTag allTags()

有关详细信息,请参阅以下链接

[http://forum.spring.io/forum/spring-projects/data/nosql/724397-mapping-exception-with-mongodb-aggregation-framework][1]

另请参阅Mongo Issue fixed

[https://jira.spring.io/browse/DATAMONGO-229]