-
Feb 11th, 2008, 09:53 PM
#1
Problem with AOP in struts+spring application
Hi,
I am using spring+struts application and want to apply advice on struts action classes.
As you know there are two ways to integrate spring with struts. Either include ContextLoaderPlugIn
in struts-config.xml or use spring Action classes.
I am using Spring Action classes. I have given entry in web.xml as shown below:
web.xml(either ContextLoaderListener or ContextLoaderServlet)
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListe ner
</listener-class>
</listener>
OR
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>
org.springframework.web.context.ContextLoaderServl et
</servlet-class>
</servlet>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/beans.xml</param-value>
</context-param>
This is my action class:
public class SearchSubmit extends ActionSupport {
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
DynaActionForm searchForm = (DynaActionForm) form;
String isbn = (String) searchForm.get("isbn");
//the old fashion way
//BookService bookService = new BookServiceImpl();
//ServletContext sc = getServletContext();
ApplicationContext ctx = getWebApplicationContext();
//ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicati onContext(sc);
BookService bookService = (BookService) ctx.getBean("bookService");
Book book = bookService.read(isbn.trim());
....
....
beans.xml::
....
<aop:config>
<aop:aspect ref="LoggingAspect">
<!-- <aop
ointcut id="myCutLogging" expression="execution(* ca.nexcel.books.actions.SearchSubmit.execute(..))"/> -->
<!-- expression="execution(* ca.nexcel.books.business.BookService*.*(..))" /> -->
<aop
ointcut id="myCutLogging" expression="execution(* ca.nexcel.books.business.BookService*.*(..))"/>
<aop:around pointcut-ref="myCutLogging" method="log" />
</aop:aspect>
</aop:config>
...
When i am using ContextLoaderListner then when i start the tomcat, i am getting Error Listener start
and when i use ContextLoaderServlet, tomcat starts successfully but when i navigate in application, it throws
excetion that WebApplicationContext is not found.Is ContextLoaderListner registered?
Please help me to solve this issue.
Thanks in advance.
Mukesh
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules