0

I'm trying to add the aws-xray-recorder-sdk-spring lib to an existing spring boot service, as described in the docs here.

I get this error on startup:

{"@timestamp":"2018-05-08T08:04:23.026+10:00","@version":1,"message":"Application run failed","logger_name":"org.springframework.boot.SpringApplication","thread_name":"main","level":"ERROR","level_value":40000,"stack_trace":"org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'meterRegistryPostProcessor' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/MetricsAutoConfiguration.class]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: warning no match for this type name: org.springframework.data.repository.Repository [Xlint:invalidAbsoluteTypeName]
\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:591)
\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:502)
\tat org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:312)
\tat org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
\tat org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310)
\tat org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:205)
\tat org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:238)
\tat org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:709)
\tat org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:534)
\tat org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)
\tat org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752)
\tat org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:388)
\tat org.springframework.boot.SpringApplication.run(SpringApplication.java:327)
\tat org.springframework.boot.SpringApplication.run(SpringApplication.java:1246)
\tat org.springframework.boot.SpringApplication.run(SpringApplication.java:1234)
\tat net.nxbos.vti.Application.main(Application.java:34)
Caused by: java.lang.IllegalArgumentException: warning no match for this type name: org.springframework.data.repository.Repository [Xlint:invalidAbsoluteTypeName]
\tat org.aspectj.weaver.tools.PointcutParser.parsePointcutExpression(PointcutParser.java:319)
\tat org.springframework.aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression(AspectJExpressionPointcut.java:226)
\tat org.springframework.aop.aspectj.AspectJExpressionPointcut.obtainPointcutExpression(AspectJExpressionPointcut.java:197)
\tat org.springframework.aop.aspectj.AspectJExpressionPointcut.getClassFilter(AspectJExpressionPointcut.java:176)
\tat org.springframework.aop.support.AopUtils.canApply(AopUtils.java:224)
\tat org.springframework.aop.support.AopUtils.canApply(AopUtils.java:283)
\tat org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:315)
\tat org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findAdvisorsThatCanApply(AbstractAdvisorAutoProxyCreator.java:124)
\tat org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:93)
\tat org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:74)
\tat org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:352)
\tat org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:304)
\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:438)
\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1714)
\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:583)
\t... 15 common frames omitted
"}

I have set the Interceptor to run on classes annotated with @XRayEnabled like so

  @Override
  @Around("@annotation(com.amazonaws.xray.spring.aop.XRayEnabled)")
  public void xrayEnabledClasses() {}

I don't have spring-data in my project so a little confused as to why AOP is trying to match on it.

Theres a post here that mentions the Thread local usage on startup could be to blame, and suggests instrumenting manually. Would prefer to use the AWS SDK if possible, any ideas on the above error?

The AWS X-Ray Recorder SDK relies on InheritableThreadLocal storage in order to propagate information about the current (sub)segments throughout the program's execution. It seems that Spring is using a pre-instantiated ThreadPoolExecutor to run its Bean creation tasks. Thus, the "InitializerListener" segment, after being created on an alternate thread, is not available to the I18nCache initializing function.

Jimmy
  • 16,123
  • 39
  • 133
  • 213
  • I have no idea about Spring or AWS, but a quick look into the GitHub repo shows that you do have _spring-data-commons_ in your project as a transitive dependency of _aws-xray-recorder-sdk-spring_ according to the [POM](https://github.com/aws/aws-xray-sdk-java/blob/master/aws-xray-recorder-sdk-spring/pom.xml#L50). Is that any helpful? Then I can convert this into an answer. BTW, `mvn dependency:tree` and often also `mvn dependency:analyze` are your friends. – kriegaex May 08 '18 at 04:27
  • Hello, I would appreciate some feedback as I was trying to help you. – kriegaex May 13 '18 at 07:39
  • @kriegaex I couldn't get this lib to play nicely, so I ended up removing the auto instrumentor, and created my own library/annotation for instrumenting XRay. It was a case of adding a request handler to the AWS SDK clients, then using the annotation to wrap the begin/end segment – Jimmy May 19 '18 at 11:12
  • Then please either add a comprehensive answer with a solution and accept it in order to close the question or just delete the question. You know how SO works, you have 7.7k reputation. – kriegaex May 19 '18 at 12:03

1 Answers1

3

I was facing the same issue. I found out that my project was missing spring-data-commons dependency. As a result, we are encountering ClassNotFoundException for org.springframework.data.repository.Repository. The exception gets masked by Spring AOP. My issue got fixed once I added this dependency.