我想知道是否搞亂了我所有的代碼,或者我的解決方案是否可以接受:我有一個EJB,我們稱之爲Customer。客戶由其他EJB,Primefaces頁面(在同一個JVM中)和一個servlet(可能在同一個JVM中,也許不是)使用。 所以我編寫這樣的:EJB:@remote,@local和@localbean,所有這些都是正確的?
// this is in RemoteIntefaces.jar
@Remote
public interface CustomerRemote {
public methodA();
}
// this is in LocalInterfaces.jar
@Local
public interface CustomerLocal {
public methodB();
}
// this is in the EJB project
@Stateless
@LocalBean
public class Customer implements CustomerRemote, CustomerLocal {
@Override
public methodA() {
[...]
}
@Override
public methodB() {
[...]
}
public methodC() {
[...}
}
}
了methodA遠程調用,從servlet,使用RemoteInterfaces.jar:
@EJB
private CustomerRemote customer;
[...]
public myFunction() {
customer.methodA();
}
的methodB從primefaces烘焙豆調用,使用LocalInterfaces.jar:
@EJB
private CustomerLocal customer;
[...]
public myFunction() {
customer.methodB();
}
methodC在同一個EJB項目由另一個EJB:
@EJB
private Customer customer;
[...]
public myFunction() {
customer.methodC();
}
我不想methodC暴露於外部接口,所以我決定不把它放在任何接口
豈不等於工作正常,但我不知道這是否是正確的,或者如果這是一個不好的做法,或者它有一些負面影響。 這不是關於「我認爲它很好」,我已經有一個意見,關鍵是如果存在任何關於「實現所有可能的意見」的文檔:P
謝謝|格拉西亞斯|古拉爵
是的,「有點」,但在現實生活中,我發現有更多的「典型」使豆有兩個視圖。就我個人而言,我認爲這是可以的,這是正常的,必須從UI和內部訪問您的「客戶」邏輯(我想例如關於customer.load(idCustomer)...) – 2014-10-01 13:47:11
根據我的經驗,我同意通常是bean只公開一個客戶端視圖,但可能取決於每個項目需求。 – 2014-10-01 14:34:53
我已經閱讀過使用Local和Remote註釋一個bean的地方,但是如果一個bean實現兩個不同的接口,一個使用Local註釋,另一個使用Remote註釋可以。 我要管理員,我有點困惑什麼是反模式或不關於豆的意見... – 2014-10-01 15:01:27