gpt4 book ai didi

java - UNC路径 "does not denote a properly accessible directory"异常如何解决?

转载 作者:行者123 更新时间:2023-11-30 10:49:48 27 4
gpt4 key购买 nike

实现 Spring Integration 的 Spring boot 应用程序正在尝试为其入站 channel 适配器访问 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 注入(inject)。

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

最佳答案

关于此事的配置最好分享一下。 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 实际上应该是绝对路径,而不是相对路径。

更新

参见 java.io.File JavaDocs:

* <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.

关于java - UNC路径 "does not denote a properly accessible directory"异常如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35297455/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com