5

私は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 はインターフェイスです。代わりに ArrayList または LinkedList を使用してください

しかし、私の質問は、上記のコードが常にエラーになるとは限らないのはなぜですか?

上記のエラーが発生した場合、どのようにページを更新してもエラーは続き、決して消えることはありません!しかし、Tomcat を再起動すると、このエラーを解決する良い機会になります!上記のようなエラーが発生しない場合は、次のユーティリティを使用してエラーが発生することはありませんトムキャット再起動!

int または Integer 型の @ModelAttribute と同様に、エラーになる可能性が非常に高くなりますが、一部のホストでは発生しません。

4

1 に答える 1

-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 ]

于 2018-03-01T11:11:45.973 に答える