Struts json格式返回

  • Post author:
  • Post category:其他


16:57:17,751 ERROR com.opensymphony.xwork2.DefaultActionInvocation:198 – There was an exception while instantiating the result of type org.apache.struts2.json.JSONResult

org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘org.apache.struts2.json.JSONResult’: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: com/opensymphony/xwork2/util/logging/LoggerFactory



at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:254)



at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:925)



at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowire(AbstractAutowireCapableBeanFactory.java:308)



at com.opensymphony.xwork2.spring.SpringObjectFactory.buildBean(SpringObjectFactory.java:146)



at com.opensymphony.xwork2.spring.SpringObjectFactory.buildBean(SpringObjectFactory.java:129)



at com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:143)



at com.opensymphony.xwork2.ObjectFactory.buildResult(ObjectFactory.java:220)



at com.opensymphony.xwork2.DefaultActionInvocation.createResult(DefaultActionInvocation.java:195)



at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:342)



at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:253)



at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:221)



at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)



at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)



at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)



at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)



at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)



at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:150)



at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:48)



at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)



at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)



at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)



at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)



at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)



at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:123)



at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)



at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)



at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)



at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)



at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:184)



at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)



at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)



at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)



at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)



at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)



at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:105)



at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)



at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)



at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)



at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)



at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:83)



at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)



at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)



at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)



at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)



at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:207)



at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)



at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)



at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)



at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)



at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:74)



at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)



at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)



at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)



at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)



at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:127)



at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)



at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)



at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)



at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)



at org.apache.struts2.interceptor.ProfilingActivationInterceptor.intercept(ProfilingActivationInterceptor.java:107)



at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)



at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)



at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)



at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)



at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:206)



at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)



at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)



at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)



at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)



at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:115)



at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)



at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)



at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)



at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)



at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:143)



at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)



at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)



at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)



at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)



at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:121)



at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)



at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)



at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)



at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)



at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)



at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:170)



at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)



at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)



at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)



at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)



at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:123)



at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)



at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)



at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)



at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)



at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)



at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)



at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)



at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)



at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)



at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:50)



at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:504)



at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:422)



at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)



at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)



at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)



at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)



at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)



at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)



at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)



at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)



at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)



at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)



at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)



at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)



at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)



at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)



at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)



at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)



at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)



at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)



at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)



at java.lang.Thread.run(Thread.java:745)

这是我的struts.xml

<?xml version="1.0" encoding="UTF-8"?>  
<!DOCTYPE struts PUBLIC  
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"  
    "http://struts.apache.org/dtds/struts-2.0.dtd">  
  
<struts>  
    <!-- 注意这里扩展不再是 struts-default,而是 json-default -->  
    <package name="goods" extends="json-default">  
   		 <action name="findPunchCard" class="org.com.goods.action.PunchCardAction" method="findPunchCard">
        	<result name="findSuccess">/test.jsp</result>
        </action>
        <!-- 返回结果类型为 json -->  
        <action name="userJson" class="org.com.goods.action.UserAction" method="userJson">  
            <result type="json"/>  
        </action>
    </package>  
</struts>

package org.com.goods.action;

import com.opensymphony.xwork2.ActionSupport;
import org.com.goods.service.impl.user;
import org.apache.struts2.json.annotations.JSON;
import org.apache.struts2.json.JSONResult;

@SuppressWarnings("serial")  
public class UserAction extends ActionSupport {  
  
    private user user; 
    @JSON(name="USER") 
    public user getUser() {  
        return user;  
    }  
  
    public void setUsers(user user) {  
        this.user = user;  
    }  
  
    @Override  
    public String execute() throws Exception {  
        user = new user();  
        user.setUserId(1);  
        user.setuserName("ctojxzsycztao");  
        user.setsex("男人");
        return SUCCESS;  
    } 
} 

上面的是加载的包

就解决上面的报错



版权声明:本文为u014764449原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。