How to write spring AOP for jax-rs -


i beginner in spring aop. requirement log before invoketestserver method execution.please find code below:

application-context.xml

<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans"     xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:context="http://www.springframework.org/schema/context"     xmlns:util="http://www.springframework.org/schema/util" xmlns:mvc="http://www.springframework.org/schema/mvc"     xmlns:aop="http://www.springframework.org/schema/aop" xmlns:oxm="http://www.springframework.org/schema/oxm"     xmlns:tx="http://www.springframework.org/schema/tx"     xsi:schemalocation="                         http://www.springframework.org/schema/beans                          http://www.springframework.org/schema/beans/spring-beans.xsd                         http://www.springframework.org/schema/mvc                          http://www.springframework.org/schema/mvc/spring-mvc.xsd                         http://www.springframework.org/schema/util                          http://www.springframework.org/schema/util/spring-util.xsd                         http://www.springframework.org/schema/context                          http://www.springframework.org/schema/context/spring-context.xsd                         http://www.springframework.org/schema/aop                         http://www.springframework.org/schema/aop/spring-aop.xsd                         http://www.springframework.org/schema/oxm                          http://www.springframework.org/schema/oxm/spring-oxm.xsd                         http://www.springframework.org/schema/tx                         http://www.springframework.org/schema/tx/spring-tx.xsd">      <aop:aspectj-autoproxy expose-proxy="true" />      <context:component-scan base-package="mypackage.service" />      <bean id="loggingaspect" class="mypackage.spring.inputacceptoraspect" />  </beans> 

as trying integrate aop jax-rs dont have specific bean initialized

please find below component

package mypackage.service;  @component public class firstprocess {      public response invoketestserver() throws testserverexception{             //logic         return response;     } } 

my aspect below package mypackage.spring;

@aspect

public class inputacceptoraspect {      @before("execution(*mypackage.service.invoketestserver(..))")     public void logbeforeinvokingtestserver(joinpoint joinpoint){         logger.error("testserver got invoked");         system.out.println("testserver got invoked");     } } 

and trying test below main class

package mypackage.spring;  import org.springframework.context.applicationcontext; import org.springframework.context.support.classpathxmlapplicationcontext;  import mypackage.service.firstprocess;      public class testaop {          public static void main(string args[])         {             applicationcontext context = new classpathxmlapplicationcontext("application-context.xml");             firstprocess manager = context.getbean(firstprocess.class);             manager.invoketestserver();         }     } 

while executing above getting exception failed create bean firstprocess defined in file..

any appreciated.

in class firstprocess.java trying create bean annotations annotation config not present inside configuration. add tag inside application-context.xml file bean creation using annotation config


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -