すべてのアノテーションなしでシンプルなJavaクラスを使用しています。通常のスタンドアロンアプリケーションで使用する場合、インスタンスを作成して使用するために 'New'キーワードを使用します。オブジェクトはヒープ上に作成されます。 インスタンス化されていない場合、私は静的メンバーにアクセスしたり、静的メンバーを使用したりできます。ライフサイクルEJBコンテナ内の単純なJavaクラス/オブジェクト
私はこの単純なクラスをEJBコンテナにデプロイするとどうなりますか? Stateless
またはStateful
またはEntity
に注釈を付けていないので、コンテナでどのように管理していますか。以下はサンプルコードです。ここではPOJO(ClientCounterは)特別な何もしませんが、あくまでも一例です:
@Stateless
public class WelcomeBean implements WelcomeBeanRemote {
private ClientCounter pojo = new ClientCounter();
@Override
public void showMessage() {
System.out.println("welcome client");
pojo.increment();
}
}
class ClientCounter {
private int count;
public void increment() {
count++;
}
}
クライアントは次のとおりです。
public class Client {
public static void main(String []args) {
Properties jndiProps = new Properties();
jndiProps.put(Context.INITIAL_CONTEXT_FACTORY,"org.jboss.naming.remote.client.InitialContextFactory");
jndiProps.put(Context.PROVIDER_URL,"http-remoting://localhost:8080");
jndiProps.put("jboss.naming.client.ejb.context", true);
jndiProps.put(Context.SECURITY_PRINCIPAL, "admin");
jndiProps.put(Context.SECURITY_CREDENTIALS, "admin");
final String appName = "";
final String moduleName = "EJBProject02";
final String sessionBeanName = "WelcomeBean";
final String viewClassName = WelcomeBeanRemote.class.getName();
Context ctx = new InitialContext(jndiProps);
WelcomeBeanRemote bean =(WelcomeBeanRemote) ctx.lookup(appName+"/"+moduleName+"/"+sessionBeanName+"!"+viewClassName);
bean.showMessage();
System.exit(0);
}
}
pojoファイルの編成を耳に入れてください。どのように組み立てられ、どのようにアプリケーションのどの部分にアクセスできるのか? – SacJn
サンプルコードを追加しました – gero
あなたが間違っていると仮定しています。 **この単純なクラスをEJBコンテナにデプロイしない*。アプリケーションをJava EEアプリケーションサーバー(WildFly、TomEE、Glassfishなど)にデプロイすると、すべてのEJBがアプリケーションサーバー内のEJBコンテナによって管理されます。 POJOは 'ClientCounter'として、通常のJavaプログラム上の通常のJavaクラスとしてclassloaderによって管理されます。 @Will Hartung作[この回答](http://stackoverflow.com/a/8088403/1346996)を見てください。 – aribeiro