Jdbc 为帮助器类注释数据源
我在MDB中声明了一个资源依赖项,该依赖项将由中的帮助器类使用Jdbc 为帮助器类注释数据源,jdbc,annotations,ejb-3.0,Jdbc,Annotations,Ejb 3.0,我在MDB中声明了一个资源依赖项,该依赖项将由中的帮助器类使用 @MessageDriven(name = "BazaarBillingMDB", mappedName = "jms/EJB3Queue", activationConfig = { @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"), @ActivationConfigProp
@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();
然而,当helper类试图获取数据源的句柄时,我总是面临一个NamingException。
但是,当将此数据源作为资源注入另一个EJB中时,它可以正常工作。
需要做什么才能让helper类访问到资源?请在帖子中包括printStackTrace,如果可能的话也包括helper类。我很好奇:为什么你要实例化一个helper类,而不是将其作为EJB并注入MDB?