对于使用JSF作为用户界面并包含6k+类的企业级应用程序来说,加载时编织(LTW)是一个很好的选择吗?必须为整个应用程序生成性能指标,但不能为LoginMBean等JSF托管Bean生成性能指标。然而,@Component是存在的,所以它有可能与AspectJ(LTW)一起工作吗?将添加aop.xml,并将aspectJWeaver路径添加到vm参数。
<aspectj>
<weaver
options=" -verbose -showWeaveInfo -Xset:weaveJavaxPackages=true -Xreweavable">
<include within="com.x.login..*" />
<include within="com.x.aspects.Aspect" />
</weaver>
<aspects>
<aspect name="com.x.aspects.Aspect" />
</aspects>
</aspectjpackage com.x.login;
@Component
@Scope("session")
public class LoginMBean extends AbstractMbean {
@Autowired
LoginService loginService ;
public void loginUserData(){
LoginInfo info= new LoginInfo();
//setter for info object
//some nested method calls
loginService.insertLoginData(info);
}
}package com.x.login.service.impl;
@Service("LoginService")
public class LoginServiceImpl implements LoginService{
@Autowired
GenericCrudService genericCrudService ;
public void insertLoginData(LoginInfo info){
//some nested method calls
try{
genericCrudService.saveEntity(info);
}catch(Exception e){
//log exception
}
}
}package com.x.aspect.config;
@Configuration
@ComponentScan(basePackages = { "com.x" })
@EnableLoadTimeWeaving(aspectjWeaving=AspectJWeaving.ENABLED)
public class AspectConfig {
}package com.x.aspects;
@Component
@Aspect
public class Aspects {
private static Logger Logger= LoggerFactory.getLogger(Aspects.class);
@Pointcut("execution(* *(..)) && cflow(execution(* com.x.login..*(..)))")
public void methodsToBeProfiled() {}
@Around("methodsToBeProfiled()")
public Object methodsToBeProfiled(ProceedingJoinPoint point) throws Throwable {
StopWatch sw = new StopWatch(getClass().getSimpleName());
try {
sw.start(point.getSignature().getName());
return point.proceed();
} finally {
sw.stop();
Logger.info("Elapsed Time, Package Name, Method Name");
Logger.info(sw.prettyPrint());
Logger.info("Package Name: " + point.getStaticPart());
}
}
}AspectJ日志:
[ParallelWebappClassLoader@17c8dbdf] info register aspect com.x.aspects.Aspects
[ParallelWebappClassLoader@17c8dbdf] info register aspect org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect
[ParallelWebappClassLoader@17c8dbdf] info register aspect org.springframework.scheduling.aspectj.AnnotationAsyncExecutionAspect
[ParallelWebappClassLoader@5e68f202] weaveinfo Join point 'method-execution(void com.x.aspects.Aspects.methodsToBeProfiled())' in Type 'com.x.aspects.Aspects' (Aspects.java:36) advised by around advice from 'com.x.aspects.Aspects' (Aspects.java) [with runtime test]
[ParallelWebappClassLoader@5e68f202] weaveinfo Join point 'method-execution(java.lang.String com.x.login.PSMVProperties.getMultiDb())' in Type 'com.x.login.PSMVProperties' (PSMVProperties.java:27) advised by around advice from 'com.x.aspects.Aspects' (Aspects.java) [with runtime test]
[ParallelWebappClassLoader@5e68f202] weaveinfo Join point 'method-execution(void com.x.login.MultiDatabase.loadAEFormRestrictions(com.x.qnccore.service.GenericCrudService, java.lang.String, org.springframework.web.context.WebApplicationContext))' in Type 'com.x.login.MultiDatabase' (MultiDatabase.java:275) advised by around advice from 'com.x.aspects.Aspects' (Aspects.java) [with runtime test]
[ParallelWebappClassLoader@5e68f202] weaveinfo Join point 'method-execution(void com.x.login.QuestionMBean.setRecordLock(boolean))' in Type 'com.x.login.QuestionMBean' (QuestionMBean.java:146) advised by around advice from 'com.x.aspects.Aspects' (Aspects.java) [with runtime test]
[ParallelWebappClassLoader@5e68f202] weaveinfo Join point 'method-execution(java.lang.String com.x.login.RequestPojo.getTenantid())' in Type 'com.x.login.RequestPojo' (RequestPojo.java:18) advised by around advice from 'com.x.aspects.Aspects' (Aspects.java) [with runtime test]
[ParallelWebappClassLoader@5e68f202] weaveinfo Join point 'method-execution(void com.x.login.RequestPojo.setTenantid(java.lang.String))' in Type 'com.x.login.RequestPojo' (RequestPojo.java:23) advised by around advice from 'com.x.aspects.Aspects' (Aspects.java) [with runtime test]
[ParallelWebappClassLoader@17c8dbdf] weaveinfo Join point 'method-execution(void com.x.login.service.impl.LoginServiceImpl.insertLoginData(com.x.agx.admin.bus.entity.LoginInfo))' in Type 'com.x.login.service.impl.LoginServiceImpl' (LoginServiceImpl.java:427) advised by around advice from 'com.x.aspects.Aspects' (Aspects.java) [with runtime test]
[ParallelWebappClassLoader@17c8dbdf] weaveinfo Join point 'method-execution(java.util.List com.x.login.service.impl.LoginServiceImpl.getFailedLoginAttemptUsingIp(java.util.HashMap))' in Type 'com.x.login.service.impl.LoginServiceImpl' (LoginServiceImpl.java:442) advised by around advice from 'com.x.aspects.Aspects' (Aspects.java) [with runtime test]spring-config.xml
<aop:aspectj-autoproxy proxy-target-class="true"></aop:aspectj-autoproxy>
<context:load-time-weaver aspectj-weaving="on" />指标日志
ms % Task name
-----------------------------------------
00003 100% insertLoginData
2019-07-30 15:14:19,550 INFO c.a.a.Aspects [http-nio-8080-exec-10] Package Name: execution(void com.x.login.service.impl.LoginServiceImpl.insertLoginData(LoginInfo))
2019-07-30 15:14:19,554 INFO c.a.a.Aspects [http-nio-8080-exec-10] Elapsed Time, Package Name, Method Name
2019-07-30 15:14:19,555 INFO c.a.a.Aspects [http-nio-8080-exec-10] StopWatch 'Aspects': running time (millis) = 4LoginMBean是为login.xhtml管理的jsf。是JSF问题还是因为错误的切入点?LoginMBean没有出现在编织类中。请帮助上面的错误。我无法获得LoginMBean类中任何方法的性能指标。
发布于 2019-07-30 21:24:14
查看您的日志,看起来LoginMBean没有公开给AspectJ编织器。至少我没有看到任何weaveinfo ... in Type 'com.x.login.LoginMBean'。所以
weaveinfo.*LoginMBean使用之后,将您的日志grep到日志下面)LoginMBean的类加载器上没有注册AspectJ编织代理。那么知道您正在使用哪个应用程序服务器以及命令JVM行是什么样子将会很有趣(应该是-javaagent:....的内容
请通过评论或通过使用更多信息更新您的问题来跟进此答案。理想情况下,在GitHub上生成并发布一个MCVE。
https://stackoverflow.com/questions/57253254
复制相似问题