首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring框架中的加载时间编织不能正确记录日志

Spring框架中的加载时间编织不能正确记录日志
EN

Stack Overflow用户
提问于 2019-07-29 19:49:08
回答 1查看 616关注 0票数 1

对于使用JSF作为用户界面并包含6k+类的企业级应用程序来说,加载时编织(LTW)是一个很好的选择吗?必须为整个应用程序生成性能指标,但不能为LoginMBean等JSF托管Bean生成性能指标。然而,@Component是存在的,所以它有可能与AspectJ(LTW)一起工作吗?将添加aop.xml,并将aspectJWeaver路径添加到vm参数。

代码语言:javascript
复制
<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>
</aspectj
代码语言:javascript
复制
package 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);

   }
}
代码语言:javascript
复制
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
      }
    }        

}
代码语言:javascript
复制
package com.x.aspect.config;

@Configuration
@ComponentScan(basePackages = { "com.x" })
@EnableLoadTimeWeaving(aspectjWeaving=AspectJWeaving.ENABLED)
public class AspectConfig {


}
代码语言:javascript
复制
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日志:

代码语言:javascript
复制
[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]
代码语言:javascript
复制
spring-config.xml

<aop:aspectj-autoproxy proxy-target-class="true"></aop:aspectj-autoproxy>
<context:load-time-weaver aspectj-weaving="on" />

指标日志

代码语言:javascript
复制
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) = 4

LoginMBean是为login.xhtml管理的jsf。是JSF问题还是因为错误的切入点?LoginMBean没有出现在编织类中。请帮助上面的错误。我无法获得LoginMBean类中任何方法的性能指标。

EN

回答 1

Stack Overflow用户

发布于 2019-07-30 21:24:14

查看您的日志,看起来LoginMBean没有公开给AspectJ编织器。至少我没有看到任何weaveinfo ... in Type 'com.x.login.LoginMBean'。所以

  • 要么装入并编织类(您可以在确定类已装入并由weaveinfo.*LoginMBean使用之后,将您的日志grep到日志下面)
  • ,要么根本不编织(如果您找不到这样的日志条目)。那么你就有了一个类加载器的问题,例如,不知何故,负责加载LoginMBean的类加载器上没有注册AspectJ编织代理。那么知道您正在使用哪个应用程序服务器以及命令JVM行是什么样子将会很有趣(应该是-javaagent:....

的内容

请通过评论或通过使用更多信息更新您的问题来跟进此答案。理想情况下,在GitHub上生成并发布一个MCVE

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57253254

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档