JBoss4.0.5GA+EJB3

Recently I always used the Spring+Hibernate+Struts frameworks to persist data into db,
But EJB3 is the standard spec of J2EE,so try to migrate JBoss4.0.5GA J2EE container to study EJB3.
Install:
1.JBoss4.0.5GA(download it ok,then unzip it in a folder)    http://jboss.org
2.Obtain the EJB3 for JBoss4.0.5GA patch, http://labs.jboss.com/portal/jbossejb3/download/index.html

3.according to the EJB3 install patch:
$ cd jboss-EJB-3.0_RC9-FD-patch1
$ ant -f install.xml -Djboss.server.config=all

4.then Run the server use below command:   
$cd jboss\bin
$ run -c all

5.Now it's time to put down your ejb3 and test codes.
for explain the progress,all the codes are very simple(stateless session bean).
EBJ3:
interface
package com.aaron.ejb3
public interface HelloWorld {
    public String SayHello(String name);
}
implement
package com.aaron.ejb3
import javax.ejb.Remote;
import javax.ejb.Stateless;

@Stateless
@Remote ({HelloWorld.class})
public class HelloWorldBean implements HelloWorld {

    public String SayHello(String name) {       
        return name +"say:Hello world this is the first EJB3";
    }

}

Write a jsp for test the EJB3:

<%@ page contentType="text/html; charset=GB2312"%>
<%@ page import="package com.aaron.ejb3.HelloWorld, javax.naming.*, java.util.Properties"%>
<%
  Properties props = new Properties();
  props.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
  props.setProperty("java.naming.provider.url", "localhost:1099");
  props.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming"); 

  InitialContext ctx;
  try {
   ctx = new InitialContext(props);
   HelloWorld helloworld = (HelloWorld) ctx.lookup("HelloWorldBean/remote");
   out.println(helloworld.SayHello("Aaron"));
  } catch (NamingException e) {
   out.println(e.getMessage());
  }
%>

6.Deploy the EJB3 and jsp
compile the EJB3 and package it for jar file,
and create a web structure including the above jsp file.
Run the jsp file.

你可能感兴趣的:(spring,Hibernate,jsp,jboss,ejb)