Announcement Announcement Module
Collapse
No announcement yet.
Problem with AOP in struts+spring application Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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">
    <!-- <aopointcut id="myCutLogging" expression="execution(* ca.nexcel.books.actions.SearchSubmit.execute(..))"/> -->
    <!-- expression="execution(* ca.nexcel.books.business.BookService*.*(..))" /> -->
    <aopointcut 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

  • #2
    If your application doesn't start you probably have a configuration issue, figure out what. Crank up the loglevel to DEBUG to see what is happening.

    Next time please use [ code][/code ] tags when posting!

    Comment

    Working...
    X