• 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

loading spring application context with struts

 
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all,
i have a very basic strut use case
myjsp ---> TestAction --> some other jsp.
In my test action i want to use hibernateDaoSupport. i just did the exact whats there in the petclinic appliction. here is the detailed code and also the configuration i did

In my TestAction.java Code
HibernateClinic cl = new HibernateClinic();
Collection col = cl.getVets();
return mapping.findForward(str);

HibernateClinic.java
public class HibernateClinic extends HibernateDaoSupport {
public Collection getVets() throws DataAccessException {
return getHibernateTemplate().find("from Vet vet order by vet.lastName, vet.firstName");
}
}

My big issue is how to make struts recogize to load spring application context for this in my web.xml i did the following
My web.xml file is the same as any other and it is left untouched
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>application</param-name>
<param-value>ApplicationResource</param-value>
</init-param>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>validate</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
i haven't changed anything here
but in struts-config.xml
i did the following according to this tutorial at IBM
http://www-128.ibm.com/developerworks/java/library/j-sr2.html

<struts-config>
<form-beans>
</form-beans>
<action-mappings>
<action
path="/Test"
type="com.action.TestAction"
input="/test.jsp">
<forward name="index" path="/test.jsp"/>
</action>
</action-mappings>
<message-resources parameter="ApplicationResources" />
<controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor"/>
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation" value="/WEB-INF/applicationContext-hibernate.xml"/>
</plug-in>

Please note how i am configuring my applicationContext-hibernate.xml file in teh contextConfigLocation property. The thing i need to know is how to hook up these application context in my struts applicaiton. i haven't changed anything in the applicationContext-hibernate.xml.
If anyone could please let me know how to approach this considering my naive expertise level in dealing with this
Thanks
Rashid
 
Rashid Darvesh
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok lets make things simpler now
i took the first approach whcih is a bit simpler
accroding to it i added the plugin in my strust config
<plug-in className= "org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property= "contextConfigLocation" value="/WEB-INF/applicationContext-hibernate.xml"/>
</plug-in>

and my action class extends ActionSupport now
now when i start my application and click on link which calls an action i get the error
HTTP Status 404 - Servlet action is not available

Any idea whats wrong now...
Rashid
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic