mai

11

EJB 3 Spring test

Posted by : admin | On : 11 mai 2012

 

The client test configuration project

 

you’re project should like like this

 

*in the classpath create a jndi.propertiesand java  class client

java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url=localhost:1099
package com.spring.client;

import javax.naming.Context;
import javax.naming.InitialContext;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.ejb.domain.Customer;
import com.ejb.service.CustomerService;
import com.spring.service.CustomerManager;

public class SpringAndEJBMain {

    public static void main(String[] args) {

        try {
            Context context = new InitialContext();
            CustomerService stock = (CustomerService) context.lookup("CustomerService/remote");

             ApplicationContext contextSpring =new ClassPathXmlApplicationContext("SpringXMLConfig.xml");

             CustomerManager service = (CustomerManager) contextSpring.getBean("manageCustomer");
             Customer customer = new Customer();
             customer.setFirstName("Meera");
             customer.setLastName("Subbarao");
             customer.setMiddleName("B");
             customer.setEmailId("meera@springandejb.com");
             customer.setCustomerId(new Long(1));

             service.addCustomer(customer);
             for (Customer cust : service.listCustomers()) {
                 System.out.println(cust.getFirstName());
                 System.out.println(cust.getLastName());
                 System.out.println(cust.getMiddleName());
                 System.out.println(cust.getEmailId());

             }
            // service.removeCustomer(new Long(1));

        }
        catch (Exception e) {
	         e.printStackTrace();
	      }

    }
}