@EJB(查找)因org.omg.CosNaming.NamingContextPackage.NotFound而失败

时间:2013-10-07 06:14:10

标签: jsf java-ee ejb websphere

我在Websphere 8.5上部署了一个应用程序,它提供了以下异常:

[10/6/13 22:30:18:323 PDT] 000000be InjectionBind E   CWNEN0030E: The @EJB factory encountered a problem getting the object instance com.chander.test.web.managebean.Registration/staticDataService binding object.  The exception message was: Context: chander-4ae021bNode01Cell/nodes/chander-4ae021bNode01/servers/server1, name: com.chander.test.service.api.StaticDataService: First component in name com.chander.test.service.api.StaticDataService not found.
[10/6/13 22:30:18:417 PDT] 000000be annotation    E com.ibm.ws.webcontainer.annotation.WASAnnotationHelper inject SRVE8060E: An unexpected exception occurred during resource injection.
                                 com.ibm.wsspi.injectionengine.InjectionException: Unable to obtain an instance for com.chander.test.web.managebean.Registration/staticDataService: javax.naming.NameNotFoundException: Context: chander-4ae021bNode01Cell/nodes/chander-4ae021bNode01/servers/server1, name: com.chander.test.service.api.StaticDataService: First component in name com.chander.test.service.api.StaticDataService not found. [Root exception is org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0]
    at com.ibm.wsspi.injectionengine.InjectionBinding.getInjectionObject(InjectionBinding.java:1123)
    at com.ibm.ws.ejb.injection.processor.EJBInjectionBinding.getInjectionObject(EJBInjectionBinding.java:1101)

以下是注册类:

@SuppressWarnings("serial")
@ManagedBean(name = "registration")
@SessionScoped
public class Registration implements Serializable {

    private static final Logger log = LoggerFactory.getLogger(Registration.class);

    private UserRegistrationForm form = new UserRegistrationForm();

    @EJB(lookup = "com.chander.test.service.api.StaticDataService")
    private StaticDataService staticDataService;

    public StaticDataService getStaticDataService() {
        return staticDataService;
    }

    public UserRegistrationForm getForm() {
        return form;
    }

    public void setForm(UserRegistrationForm form) {
        this.form = form;
    }

    // navigation

    public String toFirstPage() {
        log.info("Registration First Page");

        return "REGISTRATION_FIRST_PAGE";
    }

    public String toSecondPage() {
        log.info("Registration Second Page");

        return "REGISTRATION_SECOND_PAGE";
    }

}

的persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
    version="2.0">

    <persistence-unit name="chander.test" transaction-type="JTA">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jta-data-source>oracle/chander_datasource</jta-data-source>

        <class>com.chander.test.dao.model.UserProfile</class>
        <class>com.chander.test.dao.model.CreditCard</class>
        <class>com.chander.test.dao.model.Address</class>
        <class>com.chander.test.dao.model.Country</class>

        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
            <property name="hibernate.hbm2ddl.auto" value="none" />

            <property name="hibernate.transaction.factory_class"
                value="org.hibernate.transaction.CMTTransactionFactory" />
            <property name="hibernate.transaction.manager_lookup_class"
                value="org.hibernate.transaction.WebSphereExtendedJTATransactionLookup" />

            <property name="hibernate.show_sql" value="false" />
            <property name="hibernate.format_sql" value="false" />
            <property name="hibernate.use_sql_comments"  value="false"/>
        </properties>
    </persistence-unit>
</persistence>

2 个答案:

答案 0 :(得分:0)

我猜com.chander.test.service.api.StaticDataService是EJB类或接口的名称。 lookup注释的@EJB参数采用JNDI路径。

我不知道Websphere 8如何将EJB放在JNDI上下文中,但你确定这是正确的吗?您是否尝试过lookup,即:

@EJB
private StaticDataService staticDataService;

答案 1 :(得分:0)

正如您的例外情况所示

com.chander.test.service.api.StaticDataService not found

StaticDataService应该是一个接口,并使用@Remote(javax.ejb.Remote)注释进行注释。还要在Web项目的类路径中添加您的ejb项目。现在使用@EJB来获取接口的引用。 http://docs.oracle.com/javaee/6/api/javax/ejb/EJB.html

@EJB
private StaticDataService staticDataService;

根据我的知识查找用于包含目标EJB组件的JNDI名称的可移植查找字符串。

您可以参考

http://www-01.ibm.com/support/docview.wss?uid=swg21382740