我有一个独立的弹簧应用程序与嵌入式Apache FTP服务器。这个配置看起来是这样的 -Spring配置自定义命名空间
<?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:afs="http://mina.apache.org/ftpserver/spring/v1"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://mina.apache.org/ftpserver/spring/v1 http://mina.apache.org/ftpserver/ftpserver-1.0.xsd">
<context:property-placeholder location="classpath:config.properties" system-properties-mode="OVERRIDE"/>
<afs:server id="server" anon-enabled="false">
<afs:listeners>
<afs:nio-listener name="default" port="2222"
idle-timeout="60" />
</afs:listeners>
<!-- other AFS config -->
</afs:server>
</beans>
我想从属性文件加载的nio-listener
的port
财产,但
<afs:nio-listener name="default" port="${ftp.port}"
idle-timeout="60" />
不起作用,因为port
在XSD定义为xs:int
。我想知道是否有任何解决方法(使用SpEL?),这将允许我使用AFS名称空间和从文件或系统属性中加载port属性。
我知道哪些类对应的自定义标签,但因为'port'是一个构造ARG并没有一个二传手'财产override'不是解决办法。我不确定我了解您的其他建议,即禁用应用程序上下文中的验证。你能否详细说明一下?这里的问题是'port'属性不仅在xsd中被声明为int,而且在java类中也被声明为int。 – Vivek 2013-04-05 05:07:13
我试过context.setValidating(false),它工作正常,但在BeanDefinitonParser中失败,甚至在它到达PropertyPlaceholderConfigurer之前。原因是BeanDefinitonParser将port属性解析为int,而不是将其作为String传递给PropertyPlaceholderConfigurer以稍后解析。 – Vivek 2013-04-05 12:54:59
这会导致java.lang.NumberFormatException异常:对于输入字符串:“$ {ftp.port}”'。我开始认为没有简单的方法来做到这一点...... – Vivek 2013-04-05 13:00:28