无法查找EJB,无法在WebLogic Server 12c中部署EJB

时间:2016-02-26 14:21:40

标签: java xml java-ee

当我在weblogic 12c上运行没有ejb-jar.xml的项目时,它运行良好... 但是当我包含这个ejb-jar.xml时,它给了我错误

  

"替换为缺少的类在EJB ejb3.1中,必须指定远程主目录和远程组件接口。目前,只指定了其中一个。"

当我在Jboss 6.4上使用相同的ejb-jar.xml时,这个项目运行正常。

请协助。

Hello.java

 package com.end;

import javax.ejb.Remote;
@Remote
    public interface Hello{ 
    public String hello(String h);
}

HelloBean.java

package com.end;
import javax.ejb.Stateless;

@Stateless
public class HelloBean implements Hello {

public String hello(String h) {
System.out.println("server hello"); 
return "client " + h + "  !";
    }
}

客户端代码 Print.java

package com.end;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
public class Print 
{

public static void main(String[] args) {
        Hello hel = null;
        Date d = new Date();

        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        String strDate = dateFormat.format(d);
        Properties p = new Properties();

        p.put(Context.INITIAL_CONTEXT_FACTORY,
                "weblogic.jndi.WLInitialContextFactory");
        p.put(Context.PROVIDER_URL, "t3://localhost:7005");

        try {
            InitialContext ctx = new InitialContext(p);
            hel = (Hello) ctx.lookup("Hello#com.end.Hello");
            System.out.println(hel.hello(strDate));
            } 
        catch (Exception e) {
            e.printStackTrace();
        }
    }
}

现在是 ejb-jar.xml

?xml version="1.0" encoding="UTF-8"?>                                        <ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:ejb="http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd"

    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd"
    version="3.1">

    <enterprise-beans>

        <session>

            <ejb-name>HelloBean</ejb-name>

            <remote>com.end.Hello</remote>

            <ejb-class>com.end.HelloBean</ejb-class>

            <session-type>Stateless</session-type>

            <transaction-type>Container</transaction-type>

        </session>

    </enterprise-beans>

</ejb-jar>

0 个答案:

没有答案