0

我在我的 MDB 中声明了一个资源依赖项,它将由其中的帮助程序类使用。

@MessageDriven(name = "BazaarBillingMDB", mappedName = "jms/EJB3Queue", activationConfig = {
    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
    @ActivationConfigProperty(propertyName = "destinationName", propertyValue = "jms/EJB3Queue") }
)
@Resource(name="EJB3Source",mappedName="jdbc/EJB3Source",type=javax.sql.DataSource.class)
public class BazaarBillingMDB implements MessageListener {
    public void onMessage(Message message) {
        try {
            TextMessage msg = (TextMessage) message;
            String order = (String) msg.getText();
            try {
                bazaarhelper helper=new bazaarhelper();
                helper.insertBilling(order);
            } 
....
}

助手类(bazaarhelper)试图获取这个数据源的句柄:

try {
            context=new InitialContext();
            dataSource = (DataSource)context.lookup("java:comp/env/EJB3Source");
            conn = dataSource.getConnection();          

但是,当助手类尝试获取数据源的句柄时,我总是面临 NamingException。但是,当作为资源注入另一个 EJB 时,此数据源可以正常工作。需要做什么才能让辅助类可以访问资源?

4

0 回答 0