⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pricerbean.java

📁 想学习EJB的同学
💻 JAVA
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package ejb3.day6;import java.util.logging.Level;import java.util.logging.Logger;import javax.annotation.PostConstruct;import javax.ejb.EJB;import javax.ejb.Stateless;import javax.interceptor.ExcludeClassInterceptors;import javax.interceptor.ExcludeDefaultInterceptors;import javax.interceptor.Interceptors;import javax.naming.Context;import javax.naming.InitialContext;import javax.naming.NamingException;/** * * @author user */@Stateless(mappedName="ejb/pricer")@EJB(    name="ejb/taxRateDao",    beanName="TaxRateDaoBean",    beanInterface=TaxRateDaoLocal.class)@Interceptors(TimerInterceptor.class)public class PricerBean implements PricerRemote, PricerLocal {    @EJB(beanName="TaxRateDaoBean")    private TaxRateDaoLocal taxRateDaoBean;    private TaxRateDaoLocal taxRateDao;    /*     * @Resource     * private SessionContext sctx;     */        @PostConstruct    public void getRate(){        try {            Context ctx = new InitialContext();            taxRateDao = (TaxRateDaoLocal)ctx.lookup("java:comp/env/ejb/taxRateDao");            //taxRateDao = (TexRateDaoLocal)sctx.lookup("ejb/taxRateDao");        } catch (NamingException ex) {            Logger.getLogger(PricerBean.class.getName()).log(Level.SEVERE, null, ex);        }    }        @ExcludeClassInterceptors    @ExcludeDefaultInterceptors    public double getTaxByDI(String province, double cost) {        return cost * taxRateDaoBean.getTaxRate(province);    }    public double getTaxByLookup(String province, double cost) {        return cost * taxRateDao.getTaxRate(province);    }    public void initTaxRate() {        taxRateDaoBean.doSomeStuff();    }       }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -