We all use simple Java classes without any annotation. When we use it in normal standalone application, we use 'New' keyword to create instance and use it.The object is created on heap. If its not instantiated i can still access or use its static members.
My question is, if i deploy this simple class to EJB container, then what happens to it? I have not annotated it Stateless
or Stateful
or Entity
, so how container manages it. Below is sample code. The POJO here (ClientCounter) does nothing special but is just for example:
@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++;
}
}
And the client is:
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);
}
}