dependency injection - Spring AOP: passing parameters for logging -
we using org.springframework.beans.factory.beanfactoryaware
run chain of commands. services of scheme utilize 1 service audit logging. audit logging service needs unique identifier set in our implementation of beanfactoryaware
.
right unique identifier beingness passed downwards in each , every function call. 1 alternative have type of context object pass around. preferiable not because create services less useable other parts of scheme doesn't know beanfactoryaware
system.
is there aop way of implementing cleaner solution? 1 audit logging can unique identifier without code between beanfactoryaware
, audit code knowing value?
per request, here code:
public class chainrunner implements beanfactoryaware { public int runchain(string chainname, object initparameters, int msglinkid) throws exception { ourcontext ctx = createcontext(initparameters); ctx.setmsglinkid(msglinkid); createchain(chainname).execute(ctx); homecoming retval; } } public class aserviceimpl implements aservice { private loggingservice logger; public loggingservice getlogger() { homecoming logger; } public void setlogger(loggingservice logger) { this.logger = logger; } public void amethod(object params, int msglinkid) { // lots of code snipped logger().saveactiona( msglinkid, otherparams); } } public interface loggingservice { public void saveactiona(int msglinkid, object otherparams); }
chainrunner adds msglinkid chain's context. each message pull the msglinkid out of context , pass integer parameter downwards service, such aserver.amethod. service needs log activity on loggerservice, passing parameters beingness logged, first parameter msglinkid.
as stands now, services wired via xml configuration:
<bean id="loggerservice" class="com.nowhere.loggingserviceimpl"/> <bean id="aservice" class="com.nowhere.aserviceimpl"> <property name="logger" ref="loggerservice" /> </bean>
so question is: possible utilize aop msglinkid jump downwards loggingservice without having pass through many layers of services?
spring dependency-injection aop aspectj aspect
No comments:
Post a Comment