Search code examples
spring-integrationjava-6

spring-integration-file using java 1.6


I am trying to run a program on voice switch that has java 1.6 and i can not change that .

Now when running

@Bean
    @InboundChannelAdapter(value = "fileInputChannel", poller = @Poller(fixedDelay = "5000"))
    public MessageSource<File> fileReadingMessageSource() {
        FileReadingMessageSource source = new FileReadingMessageSource();
        source.setDirectory(new File(folderPath));
        CompositeFileListFilter fileListFilter = new CompositeFileListFilter();
        fileListFilter.addFilters(new IgnoreHiddenFileListFilter());
        fileListFilter.addFilters(new FileSystemPersistentAcceptOnceFileListFilter(propertiesPersistingMetadataStore(),"cdrs"));
        fileListFilter.addFilters(new RegexPatternFileListFilter(fileRegex));
//        fileListFilter.addFilters(new LastModifiedFileListFilter()); // This is to confirm that the file did not change for the past 60 second
        source.setFilter(fileListFilter);
        return source;
    }

i am getting this error

Caused by: java.lang.NoClassDefFoundError: java/nio/file/StandardWatchEventKinds
        at org.springframework.integration.file.FileReadingMessageSource$WatchEventType.<clinit>(FileReadingMessageSource.java:411) ~[spring-integration-file-4.3.5.RELEASE.jar!/:4.3.5.RELEASE]
        at org.springframework.integration.file.FileReadingMessageSource.<init>(FileReadingMessageSource.java:117) ~[spring-integration-file-4.3.5.RELEASE.jar!/:4.3.5.RELEASE]
        at org.springframework.integration.file.FileReadingMessageSource.<init>(FileReadingMessageSource.java:123) ~[spring-integration-file-4.3.5.RELEASE.jar!/:4.3.5.RELEASE]
        at com.config.RootConfiguration.fileReadingMessageSource(RootConfiguration.java:84) ~[classes!/:0.0.1-SNAPSHOT]
        at com.config.RootConfiguration$$EnhancerBySpringCGLIB$$3f678755.CGLIB$fileReadingMessageSource$2(<generated>) ~[classes!/:0.0.1-SNAPSHOT]
        at com.config.RootConfiguration$$EnhancerBySpringCGLIB$$3f678755$$FastClassBySpringCGLIB$$22198f53.invoke(<generated>) ~[classes!/:0.0.1-SNAPSHOT]
        at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
        at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356) ~[spring-context-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
        at com.config.RootConfiguration$$EnhancerBySpringCGLIB$$3f678755.fileReadingMessageSource(<generated>) ~[classes!/:0.0.1-SNAPSHOT]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6.0_36]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.6.0_36]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.6.0_36]
        at java.lang.reflect.Method.invoke(Method.java:622) ~[na:1.6.0_36]
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
        ... 41 common frames omitted
Caused by: java.lang.ClassNotFoundException: java.nio.file.StandardWatchEventKinds
        at java.net.URLClassLoader$1.run(URLClassLoader.java:217) ~[na:1.6.0_36]
        at java.security.AccessController.doPrivileged(Native Method) ~[na:1.6.0_36]
        at java.net.URLClassLoader.findClass(URLClassLoader.java:205) ~[na:1.6.0_36]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:323) ~[na:1.6.0_36]
        at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:94) ~[filetail-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:268) ~[na:1.6.0_36]
        ... 55 common frames omitted

Can i stop using the nio watch , as it is annotated with @UsesJava7 , or i should implement my own FileReadingMessageSource


Solution

  • This is a bug; the watch service used to be an optional (external) class; it was embedded as an inner class in 4.3 to avoid some configuration issues. A work-around is to drop back to the 4.2.12 version. I opened a JIRA Issue.