0
有一個intefrace MyIntefrace。JBoss 7 ServiceLoader
系統有幾個EAR,每個EAR都有自己的intefrace實現。我需要找到沒有名稱的所有實現(?extends MyInterface)。
我決定用java.util.ServiceLoader,並創建了裏面的META-INF /服務/ com.example.MyInterface一個罐子,螞蟻這個jar可以在任何耳朵部署。
罐子爲int的init()方法中一個servlet和下面的代碼:
ServiceLoader<MyInterface > loader = ServiceLoader.load(MyInterface .class);
Iterator<MyInterface > it = loader.iterator();
但仍迭代器空..
我tryed添加服務/ com.example.MyInterface耳朵META-INF ,但結果是一樣的。
這種方法在jboss 6和tomcat中工作正常。
你找到一個解決這個問題解決了嗎? – Rhys 2013-01-02 13:48:02
每個EAR都必須具有META-INF/services/com.example.MyInterface文本文件,並列舉該EAR內的所有實現 – 2013-01-02 13:57:04
您是否在使用ServiceLoader體系結構來發現單獨的EAR部署之間的服務?即EAR1可以在EAR2中找到服務,而不會相互聲明相互之間的直接依賴關係? (通過manifest或jboss-deployment-structure.xml) – Rhys 2013-01-02 14:00:54