spring mvc - Null-Pointer Exception while using AOP -


application context file

    <!-- aspect -->     <!-- allow @component, @service, @controller, etc.. annotations -->     <context:component-scan base-package="com.piyush.cns.*" />     <aop:aspectj-autoproxy/>       <!-- allow use @autowire, @required , @qualifier annotations -->     <context:annotation-config />      <!-- logger bean -->     <bean id="logger" class="org.slf4j.loggerfactory" factory-method="getlogger">         <constructor-arg type="java.lang.string" value="com.piyush.cns" />     </bean>      <!-- aspect -->     <bean id="logaspect" class="com.piyush.cns.customer.resource.allaspects" />  </beans> 

above code application context file contain bean declaration.

controller class customersresource . class receive request initially. basic requirement validate customer object server side.

@controller @path("/customers") public class customersresource implements serializable {      private static final long serialversionuid = 1l;      @autowired     icustomerservice customerservice;      @autowired     ipartnerservice partnerservice;      @autowired     resourcehelper resourcehelper;      @autowired     private logger logger;      /**      * @request post      * @param uriinfo - absolute path      * @param customer - json request of customer add      * @return response created customer payload.  includes location header      * @throws tcexception - if customer name exist      * @description rest service add customer sent json      */     @post     @consumes(mediatype.application_json)     @produces(mediatype.application_json)     public response addcustomer(@context uriinfo uriinfo, customer customer) throws tcexception {         logger.info("entering addcustomer customer " + customer.getcustomername());         logger.debug("customer desc \t " + customer.getdescription());          multivaluedmap<string, string> queryparams = uriinfo.getqueryparameters();         string partnerid = queryparams.getfirst("partnerid");         logger.info("partner id query param : " + partnerid);         // if partnerid : null, customer type direct ie, not associated partner. implies customer type = 0         // [direct]         if (null == partnerid) {             // add direct customer             customer.setcustomertype(0);             logger.debug("customer type set : direct");         } else {             // add indirect customer             // set customer type, partner             customer.setcustomertype(1);             logger.debug("customer type set : indirect");             // check if partner exist             partner partner = partnerservice.getpartnerbyid(long.parselong(partnerid));             if (null == partner) {                 logger.error("entityresourcenotfoundexception. partner resource not found id : " + partnerid);                 throw new entityresourcenotfoundexception("", "partner resource id : " + partnerid                     + " not found add customer");             }             customer.setpartner(partner);             logger.debug("customer set partner : " + partnerid);         }         // save customer         customer = customerservice.addcustomer(customer);          // creating location header         uribuilder builder = uriinfo.getabsolutepathbuilder();         uri uri = builder.path(string.valueof(customer.getid())).build();         logger.info("exiting addcustomer customer " + customer.getcustomername());         return response             .created(uri.create(uri.tostring()))             .entity(                 resourcehelper.buildresponse(customer, status.created.tostring(),                     "customer created: " + customer.getcustomername())).build();     }    aspect class allaspects  import org.aspectj.lang.joinpoint; import org.aspectj.lang.annotation.*;  @aspect public class allaspects {      @before("execution(* com.piyush.cns.customer.resource.customersresource.addcustomer(..))")     public void logbefore(joinpoint joinpoint) {          system.out.println("logbefore() running!");         system.out.println("******");     } }     problem control flow not going inside method "logbefore(...)"of class allaspects , in class customersresource  @ method addcustomers(...) logger coming null.   please me out of issue. 


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -