Search code examples
javaspringspring-xd

Spring XD integration test fails with "Path must start with / character"


I've been looking for a way to properly test my custom modules within Spring XD, so I've been trying to mimic how Spring Xd itself tests spark processors. However, no matter how I configure with their SingleNodeApplication I continue to get the following error:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobsController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.xd.dirt.server.admin.deployment.DeploymentMessagePublisher org.springframework.xd.dirt.rest.XDController.deploymentMessagePublisher; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'deploymentMessageProducer' defined in class org.springframework.xd.dirt.server.admin.deployment.zk.DeploymentConfiguration: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.xd.dirt.server.admin.deployment.zk.ZKDeploymentMessagePublisher]: Factory method 'deploymentMessageProducer' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'deploymentQueue' defined in class org.springframework.xd.dirt.server.admin.deployment.zk.DeploymentConfiguration: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Path must start with / character

    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
    at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:139)
    at org.springframework.xd.dirt.server.singlenode.SingleNodeApplication.run(SingleNodeApplication.java:83)
    at RakeExtractorSparkTest.setup(RakeExtractorSparkTest.java:39)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
    at org.junit.rules.RunRules.evaluate(RunRules.java:20)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.xd.dirt.server.admin.deployment.DeploymentMessagePublisher org.springframework.xd.dirt.rest.XDController.deploymentMessagePublisher; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'deploymentMessageProducer' defined in class org.springframework.xd.dirt.server.admin.deployment.zk.DeploymentConfiguration: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.xd.dirt.server.admin.deployment.zk.ZKDeploymentMessagePublisher]: Factory method 'deploymentMessageProducer' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'deploymentQueue' defined in class org.springframework.xd.dirt.server.admin.deployment.zk.DeploymentConfiguration: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Path must start with / character
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
    ... 46 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'deploymentMessageProducer' defined in class org.springframework.xd.dirt.server.admin.deployment.zk.DeploymentConfiguration: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.xd.dirt.server.admin.deployment.zk.ZKDeploymentMessagePublisher]: Factory method 'deploymentMessageProducer' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'deploymentQueue' defined in class org.springframework.xd.dirt.server.admin.deployment.zk.DeploymentConfiguration: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Path must start with / character
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1192)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1116)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545)
    ... 48 more
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.xd.dirt.server.admin.deployment.zk.ZKDeploymentMessagePublisher]: Factory method 'deploymentMessageProducer' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'deploymentQueue' defined in class org.springframework.xd.dirt.server.admin.deployment.zk.DeploymentConfiguration: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Path must start with / character
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
    ... 60 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'deploymentQueue' defined in class org.springframework.xd.dirt.server.admin.deployment.zk.DeploymentConfiguration: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Path must start with / character
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:368)
    at org.springframework.xd.dirt.server.admin.deployment.zk.DeploymentConfiguration$$EnhancerBySpringCGLIB$$bf8b0dd3.deploymentQueue(<generated>)
    at org.springframework.xd.dirt.server.admin.deployment.zk.DeploymentConfiguration.deploymentMessageProducer(DeploymentConfiguration.java:155)
    at org.springframework.xd.dirt.server.admin.deployment.zk.DeploymentConfiguration$$EnhancerBySpringCGLIB$$bf8b0dd3.CGLIB$deploymentMessageProducer$13(<generated>)
    at org.springframework.xd.dirt.server.admin.deployment.zk.DeploymentConfiguration$$EnhancerBySpringCGLIB$$bf8b0dd3$$FastClassBySpringCGLIB$$8c7055eb.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:355)
    at org.springframework.xd.dirt.server.admin.deployment.zk.DeploymentConfiguration$$EnhancerBySpringCGLIB$$bf8b0dd3.deploymentMessageProducer(<generated>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
    ... 61 more
Caused by: java.lang.IllegalArgumentException: Path must start with / character
    at org.apache.curator.utils.PathUtils.validatePath(PathUtils.java:54)
    at org.apache.curator.framework.recipes.queue.QueueBuilder.<init>(QueueBuilder.java:269)
    at org.apache.curator.framework.recipes.queue.QueueBuilder.builder(QueueBuilder.java:64)
    at org.springframework.xd.dirt.server.admin.deployment.zk.DeploymentQueue.start(DeploymentQueue.java:122)
    at org.springframework.xd.dirt.server.admin.deployment.zk.DeploymentQueue.afterPropertiesSet(DeploymentQueue.java:153)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
    ... 80 more

I get that its unable to autowire a jobsController, but its always due to some (zookeeper?) path not starting with a /. Am I missing something obvious? For reference here is my @BeforeClass method that is causing everything to fail:

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration
public class RakeExtractorProcessorXdTest {

    private static SingleNodeApplication application;

    private static SingleNodeIntegrationTestSupport integrationSupport;

    // This dies
    @BeforeClass 
    public static void setUp() {
        application = new SingleNodeApplication().run("--transport", "local");
        integrationSupport = new SingleNodeIntegrationTestSupport(application);
        integrationSupport.addModuleRegistry(new SingletonModuleRegistry(ModuleType.processor,
            "rake-extractor"));
    }
}

Solution

  • The problem was that I didn't have the necessary test dependencies in my project to run a SingleNodeApplication instance. This was resolved by adding the spring-xd-module plugin into our gradle builds.

    We don't actually pull in too many Spring XD dependencies since we deploy it as a docker container, and add in our custom modules as needed in the Dockerfile.

    There were some plugin conflicts. The spring-xd-module plugin looks like a wrapper of Spring Boot and propdeps and uses old versions, and conflicted with the plain old spring-boot plugin (which was version 1.4.1, in spring-xd-module it is 1.2.3) and the io.spring.dependency-management plugin. This was fixed by restructuring the project hierarchy and throwing all of our custom XD modules into their own gradle subproject.