• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

$.getJSON giving error in Struts 2 if accessing database using Spring DI

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi I am using struts 2, spring 3.0.5 and hibernate 3.5.6

I tried using struts - json plug in to get json data from one of my action by extending json-default in my existing application as follows:
<package name="default" namespace="/" extends="json-default">

However, I do get error if I use any service class using Dependency Injection in my json action just before my return statement as follows:

************************** ERROR ***************************
[6/11/15 18:50:04:333 IST] 00000096 SystemOut O execute================================ends==
[6/11/15 18:50:04:620 IST] 00000096 SystemOut O ERROR ExceptionMappingInterceptor - org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: java.lang.reflect.InvocationTargetException
org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: java.lang.reflect.InvocationTargetException


PFA the complete error log.


**************************************************************

struts.xml

<package name="default" namespace="/" extends="json-default">

<interceptors>
<interceptor name="sessionInterceptor" class="com.city.watchlist.web.util.SessionInterceptor" />

<interceptor-stack name="appDefaultStack">
<interceptor-ref name="defaultStack">
<param name="exception.logEnabled">true</param>
<param name="exception.logLevel">ERROR</param>
</interceptor-ref>
<interceptor-ref name="sessionInterceptor"></interceptor-ref>
</interceptor-stack>

<interceptor-stack name="loginStack">
<interceptor-ref name="defaultStack">
<param name="exception.logEnabled">true</param>
<param name="exception.logLevel">ERROR</param>
</interceptor-ref>
</interceptor-stack>

</interceptors>
<action name="*RuleSetSublist" class="RuleSetSublistAction" method="{1}">
<result name="success">/jsps/subListMaintenance.jsp</result>
<result name="successLoadAdd" >/jsps/addEditSubList.jsp</result>
<result name="successSaveAdd" type="redirectAction">/loadRuleSetSublist.action</result>
<result name="refreshRuleSet">/jsps/sublistRulesetSection.jsp</result>
<result name="input" >/jsps/addEditSubList.jsp</result>
</action>
<action name="ajaxAction" class="SublistAjaxJsonAction">
<result type="json">
<param name="excludeNullProperties">true</param>
<param name="noCache">true</param>
</result</action>

*****************************************************
Basically in my addEditSubList.jsp page I will be calling $.getJSON for some front end requirement.

PFA my SublistAjaxJsonAction.java class file

***********************************
spring config file is :

<bean id="ruleSetSublistDAO" class="com.city.watchlist.ruleset.dao.RuleSetSublistDAO" parent="baseDAO"/>
<bean id="ruleSetSublistServ" class="com.city.watchlist.ruleset.service.RuleSetSublistService">
<property name="ruleSetSublistDAO" ref="ruleSetSublistDAO" />
</bean>
<bean id="RuleSetSublistAction" class="com.city.watchlist.ruleset.action.RuleSetSublistAction" scope="prototype">
<property name="ruleSetSublistServ" ref="ruleSetSublistServ" />
</bean>


<bean id="SublistAjaxJsonAction" class="com.city.watchlist.ruleset.action.SublistAjaxJsonAction" scope="prototype" >
<property name="ruleSetSublistServ" ref="ruleSetSublistServ" />
</bean>

************************************
It goes all fine just before my return statement but is giving error while returning to calling jsp(addEditSubList.jsp).
if I just use some hardcoded value and not use Dependency injection and other stuffs it works fine.



PLEASe HELP|!!!
ErrorLog_Part1.png
[Thumbnail for ErrorLog_Part1.png]
ErrorLog_Part2.png
[Thumbnail for ErrorLog_Part2.png]
SublistAjaxJsonAction.png
[Thumbnail for SublistAjaxJsonAction.png]
 
navin agarwal
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just to add:

If I change the code in my jsonaction class as :

//filteredBUMap = ruleSetSublistServ.getBUForSelectedCSIs(csiList);
filteredBUMap.put("1", "1");
filteredBUMap.put("2", "2");

and delete the instance variable ruleSetSublistServ as well.


Also, remove injection of ruleSetSublistServ from spring config then it works perfectly as expected.
 
navin agarwal
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Found 1 more thing.
Even this works well.

ApplicationContext appContext = new ClassPathXmlApplicationContext("SpringBeans.xml");
RuleSetSublistService ruleSetSublistServ = (RuleSetSublistService) appContext.getBean("ruleSetSublistServ");
filteredBUMap = ruleSetSublistServ.getBUForSelectedCSIs(csiList);


Really Not sure what is going wrong in injecting the dependency.
 
Greenhorn
Posts: 3
 
navin agarwal
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply David.
However, I am not clear with the bean definition problem in my code as it is working everywhere else in the system.


If I take the service bean as below it works perfectly fines.
ApplicationContext appContext = new ClassPathXmlApplicationContext("SpringBeans.xml");
RuleSetSublistService ruleSetSublistServ = (RuleSetSublistService) appContext.getBean("ruleSetSublistServ");

Can you please suggest?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic