我JSF託管bean(它的名稱= indexbean1)和它的代碼如下:如何從我的web應用訪問本地到EJB模塊,企業應用
package ir.ac.imamreza.Client;
import ir.ac.imamreza.common.ProductServiceLocal;
import javax.ejb.EJB;
import javax.inject.Named;
import javax.enterprise.context.RequestScoped;
import javax.naming.InitialContext;
/**
*
* @author Avarcom
*/
@Named(value = "indexbean1")
@RequestScoped
public class Indexbean1 {
private String name;
private int price;
private int count;
private String desc;
public int getCount() {
return count;
}
public String getDesc() {
return desc;
}
public String getName() {
return name;
}
public int getPrice() {
return price;
}
public void setCount(int count) {
this.count = count;
}
public void setDesc(String desc) {
this.desc = desc;
}
public void setName(String name) {
this.name = name;
}
public void setPrice(int price) {
this.price = price;
}
@EJB
private ProductServiceLocal ProductService1;
public void Add()
{
ProductService1.Add(name,price, count, desc);
}
public Indexbean1() {
}
}
而且我有類,它具有本地接口類 「ProductServiceLocal」 在我的店裏模塊如下:
package ir.ac.imamreza.common;
import java.util.List;
import javax.ejb.Local;
/**
*
* @author One God
*/
@Local
public interface ProductServiceLocal {
List<Product> getallproduct();
public int BuyProduct(long id,long number);
public void Add(String name, int price,int count,String desc);
}
///////////////////////////
,這是我的EJB MODUL實現我的Add方法在我的EJB
////////////////////
package ir.ac.imamreza.Shop;
import ir.ac.imamreza.common.Product;
import ir.ac.imamreza.common.ProductServiceRemote;
import java.math.BigDecimal;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.ejb.Stateless;
import java.sql.*;
@Stateless(mappedName="ir.ac.imamreza.Shop.ProductService")
public class ProductService implements ProductServiceLocal,ProductServiceRemote {
@Override
public int BuyProduct(long id,long number)
{
int result;
dataaccess da=new dataaccess();
result=da.exec("update tbl_product set count=count-"+number+" where id='"+id+"'");
da.Close();
return result;
}
public void Add(String name, int price,int count,String desc)
{
dataaccess da=new dataaccess();
da.exec("INSERT INTO tbl_product (name,count,price,Description) VALUES
("+name+","+price+","+count+","+desc+")");
da.Close();
}
}
我將我的EJB和我的Web應用程序來訪問我的本地方法(ADD),但是當我wan't部署我的應用我面臨着以下錯誤:
SEVERE: Exception while deploying the app [WebClient] : Cannot resolve reference Local ejb-ref name=ir.ac.imamreza.Client.Indexbean1/ProductService1,Local 3.x interface =ir.ac.imamreza.common.ProductServiceLocal,ejb-link=null,lookup=,mappedName=,jndi-name=,refType=Session
..
我認爲我的Web應用程序可以無法連接到我EJB,對於這個問題,我添加Web App和EJAB到一個企業應用程序,但我再次面對這些錯誤, PLZ請幫助我,謝謝你之前
問候