我有一個獨立的彈簧應用程序與嵌入式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