【问题标题】:Spring - factory method for PathSpring - Path 的工厂方法
【发布时间】:2012-12-03 09:43:35
【问题描述】:

我正在尝试使用静态方法Paths.get(String path) 生成一个代表java.nio.file.Path 的bean。我当前的 Spring 设置如下所示:

<bean id="myPath" class="java.nio.file.Paths" factory-method="get">
    <constructor-arg value="c:\\tmp\\" />
</bean>

但它返回一个 excpetion No matching factory method found: factory method 'get'。任何想法为什么会这样?

【问题讨论】:

  • 您使用的是什么版本的 Spring?它适用于 3.1.2。
  • 2.0,但下面的解决方案有效

标签: java spring factory factory-method


【解决方案1】:

java.nio.file.Paths.get 需要 URI。此外,这是 xml 而不是 java 不要使用 \\

试试

file:/C:/tmp/

如果您对 URI 语法有疑问,请访问 http://en.wikipedia.org/wiki/File_url

【讨论】:

  • 我不会限制不要在 XML 中使用 \\:也不要在 Java 中使用它,/ 是这样做的正确方法(独立于平台)
  • 成功了。如果我稍后将其转换为 unix 系统会怎样 - 这仍然有效吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-29
  • 1970-01-01
  • 2011-01-05
  • 2012-03-24
  • 1970-01-01
相关资源
最近更新 更多