2016-02-09 46 views
1

實現Spring集成的Spring引導應用程序試圖訪問其入站通道適配器的UNC路徑。如何解決「不表示正確可訪問的目錄」UNC路徑異常?

的問題是,我收到以下異常:

13:29:52.925 [task-scheduler-10] ERROR o.s.i.handler.LoggingHandler - 
org.springframework.messaging.MessagingException: The path 
[\\server\sharepath] does not denote a properly accessible directory. 

請問該如何解決這個問題?

集成配置

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:int="http://www.springframework.org/schema/integration" 
     xmlns:int-file="http://www.springframework.org/schema/integration/file" 
     xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd 
      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
      http://www.springframework.org/schema/integration/file http://www.springframework.org/schema/integration/file/spring-integration-file.xsd"> 

    <int-file:inbound-channel-adapter id="filesIn" directory="${input.path}" filename-regex="${file.pattern}"> 
     <int:poller id="poller" fixed-rate="500"/> 
    </int-file:inbound-channel-adapter> 

    <int-file:file-to-string-transformer input-channel="filesIn" output-channel="strings" delete-files="true" /> 

    <int:channel id="strings"/> 

    <int:service-activator input-channel="strings" 
            output-channel="output" 
            ref="handler"/> 

    <int-file:outbound-channel-adapter id="output" 
             directory="${archive.path}" 
             delete-source-files="true"/> 

    <bean id="handler" class="com.giotta.service.DataHandler"/> 

</beans> 

在此配置中使用的性質與-D注入。

例如,java jar -Dinput.path="\\\\remote_host_ip\\path\\"

回答

0

原來的UNC權限是問題。由於運行Spring啓動應用程序的Windows服務包裝程序正在運行,因爲本地用戶權限不可確定。

我將運行該服務的用戶更改爲實際用戶。這允許春季一體化表示可訪問性。

1

這將是更好地分享關於此事的配置。那一個爲inbound-channel-adapter這會導致您的問題。

讓我們來看看代碼!

DefaultDirectoryScanner

public final List<File> listFiles(File directory) throws IllegalArgumentException { 
    File[] files = listEligibleFiles(directory); 
    if (files == null) { 
     throw new MessagingException("The path [" + directory 
       + "] does not denote a properly accessible directory."); 
    } 
    return (this.filter != null) ? this.filter.filterFiles(files) : Arrays.asList(files); 
} 

protected File[] listEligibleFiles(File directory) { 
    return directory.listFiles(); 
} 

這是從那裏你看到錯誤的地方。它的原因,恰恰是在java.io.File

* @return An array of abstract pathnames denoting the files and 
*   directories in the directory denoted by this abstract pathname. 
*   The array will be empty if the directory is empty. Returns 
*   {@code null} if this abstract pathname does not denote a 
*   directory, or if an I/O error occurs. 
* 
public File[] listFiles() { 

所以,你真的應該確保你使用正確的路徑爲您的目錄。

如果您在嵌入式Servlet容器模式下運行Boot應用程序,則應考慮webapp工作目錄。在這種情況下,你的\server\sharepath確實應該是絕對路徑,而不是相對的。

UPDATE

java.io.File的JavaDoc:

* <li> For Microsoft Windows platforms, the prefix of a pathname that contains a drive 
* specifier consists of the drive letter followed by <code>":"</code> and 
* possibly followed by <code>"\\"</code> if the pathname is absolute. The 
* prefix of a UNC pathname is <code>"\\\\"</code>; the hostname and the share 
* name are the first two names in the name sequence. A relative pathname that 
* does not specify a drive has no prefix. 
+0

路徑絕對是UNC路徑。我想我已經編輯了原來那裏的IP地址。 –

+0

我回來了。顯示的文字並不是額外的\ –

+0

啊!你的意思是這樣的https://en.wikipedia.org/wiki/Path_%28computing%29。當您指定遠程共享目錄的路徑時。那麼,我們需要了解Java如何與之協同工作,首先... –

相關問題