In the EJB2.1 specification, the ejbTimeout method needs to be implemented, and of course there are also methods such as ejbPassivate and ejbRemove. In EJB3.0, you must create them only when you want to use them, otherwise you don't have to implement them.
This example has 5 files. The bean in this example is a stateless session bean:
: Business interface.
: Business implementation category. In the future, the EJBs we develop will be named in this way (add beans to the interface name).
: Test EJB's client class.
: jndi attribute file, providing access to the basic configuration properties of jdni.
:ant configuration file to compile, publish, test, and clear EJB.
The following is an introduction to the content of each file.
package .;
import ;
@Remote
public interface NewsTimer
{
public void fiveNews();
}
This interface defines the fiveNews method. If this method is called, a news will be output to the console in 5 minutes.
You don't have to configure its JNDI name, nor do you have to write its configuration file. In EJB3.0 implemented by JBOSS, you do not have to write any EJB deployment files and jboss deployment files. JBOSS uses the full name of the interface as its JNDI name by default. In the above example, its full name can be obtained by ().
package .;
import ;
import ;
import ;
import ;
import ;
@Stateless
public class NewsTimerBean implements NewsTimer
{
private @Inject SessionContext ctx;
public void fiveNews()
{
().createTimer(new Date(new Date().getTime() + 300000), "Zixuwuyou TV Station's 5-minute news column: Now 5 minutes later, it's time for the instant news program again.");
}
public void ejbTimeout(Timer timer)
{
("Time is up:%n%s%n" , ());
();
}
}
package .;
import ;
import ;
public class Client
{
public static void main(String[] args) throws NamingException
{
InitialContext ctx = new InitialContext();
NewsTimer timer = (NewsTimer) (());
();
}
}
This class is used to test the counter EJB we published. First pass
ctx = new InitialContext();
Get the context, then lookup the NewsTimer through lookup, and start the timing. .
Please run: run –c all in the bin directory and start JBOSS.
Execute ejbjar target in the Ant view of Eclipse. Or on the command line, enter this project directory, execute ant ejbjar, and publish this EJB with a package.
Execute a run target in the Ant view of Eclipse. Or on the command line, enter this project directory, execute ant run, and test this EJB.
This example has 5 files. The bean in this example is a stateless session bean:
: Business interface.
: Business implementation category. In the future, the EJBs we develop will be named in this way (add beans to the interface name).
: Test EJB's client class.
: jndi attribute file, providing access to the basic configuration properties of jdni.
:ant configuration file to compile, publish, test, and clear EJB.
The following is an introduction to the content of each file.
package .;
import ;
@Remote
public interface NewsTimer
{
public void fiveNews();
}
This interface defines the fiveNews method. If this method is called, a news will be output to the console in 5 minutes.
You don't have to configure its JNDI name, nor do you have to write its configuration file. In EJB3.0 implemented by JBOSS, you do not have to write any EJB deployment files and jboss deployment files. JBOSS uses the full name of the interface as its JNDI name by default. In the above example, its full name can be obtained by ().
package .;
import ;
import ;
import ;
import ;
import ;
@Stateless
public class NewsTimerBean implements NewsTimer
{
private @Inject SessionContext ctx;
public void fiveNews()
{
().createTimer(new Date(new Date().getTime() + 300000), "Zixuwuyou TV Station's 5-minute news column: Now 5 minutes later, it's time for the instant news program again.");
}
public void ejbTimeout(Timer timer)
{
("Time is up:%n%s%n" , ());
();
}
}
package .;
import ;
import ;
public class Client
{
public static void main(String[] args) throws NamingException
{
InitialContext ctx = new InitialContext();
NewsTimer timer = (NewsTimer) (());
();
}
}
This class is used to test the counter EJB we published. First pass
ctx = new InitialContext();
Get the context, then lookup the NewsTimer through lookup, and start the timing. .
Please run: run –c all in the bin directory and start JBOSS.
Execute ejbjar target in the Ant view of Eclipse. Or on the command line, enter this project directory, execute ant ejbjar, and publish this EJB with a package.
Execute a run target in the Ant view of Eclipse. Or on the command line, enter this project directory, execute ant run, and test this EJB.