初学EJB2,关于jboss部署local问题,老报找不到jndi,详细请看下面

草坪上升起的太阳 2012-06-02 10:57:06
ejb-jar.xml
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar id="ejb-jar_ID" version="2.1" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd">
<display-name>czp_ejb</display-name>

<enterprise-beans>
<session>
<ejb-name>Advice</ejb-name>
<local-home>com.czp.AdviceHome</local-home>
<local>com.czp.Advice</local>
<ejb-class>com.czp.AdviceBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
</ejb-jar>

jboss.xml
<?xml version="1.0"?>
<jboss>
<enterprise-beans>
<session>
<ejb-name>Advice</ejb-name>
<jndi-name>Advice</jndi-name>
</session>
</enterprise-beans>
</jboss>

web客户端:
jboss-web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jboss-web PUBLIC
"-//JBoss//DTD Web Application 2.3V2//EN"
"http://www.jboss.org/j2ee/dtd/jboss-web_4_0.dtd">
<jboss-web>
<ejb-local-ref>
<ejb-ref-name>Advice</ejb-ref-name>
<jndi-name>Advice</jndi-name>
</ejb-local-ref>
</jboss-web>


web.xml
<ejb-local-ref>
<ejb-ref-name>Advice</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local-home>com.czp.AdviceHome</local-home>
<local>com.czp.Advice</local>
<ejb-link>czp_ejb.jar#Advice</ejb-link>
</ejb-local-ref>

<servlet>
<description></description>
<display-name>MyServlet</display-name>
<servlet-name>MyServlet</servlet-name>
<servlet-class>com.czp.MyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/MyServlet</url-pattern>
</servlet-mapping>


MyServlet.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try{
InitialContext ctx = new InitialContext();
try{
AdviceHome home = (AdviceHome)ctx.lookup("Advice");

Advice advice = home.create();
advice.sayHello();
}catch(CreateException e){
e.printStackTrace();
}
}catch(NamingException e){
e.printStackTrace();
}


报错语句:
22:56:16,437 ERROR [STDERR] javax.naming.NameNotFoundException: Advice not bound
22:56:16,453 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
22:56:16,453 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
22:56:16,453 ERROR [STDERR] at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
22:56:16,453 ERROR [STDERR] at org.jnp.server.NamingServer.lookup(NamingServer.java:296)
22:56:16,453 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:667)
22:56:16,453 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627)
22:56:16,453 ERROR [STDERR] at javax.naming.InitialContext.lookup(InitialContext.java:392)
22:56:16,453 ERROR [STDERR] at com.czp.MyServlet.doPost(MyServlet.java:28)
22:56:16,453 ERROR [STDERR] at com.czp.MyServlet.doGet(MyServlet.java:21)
22:56:16,453 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
22:56:16,453 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
22:56:16,453 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
22:56:16,453 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
22:56:16,453 ERROR [STDERR] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
22:56:16,453 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
22:56:16,453 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
22:56:16,453 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
22:56:16,453 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
22:56:16,453 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
22:56:16,453 ERROR [STDERR] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
22:56:16,453 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
22:56:16,453 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
22:56:16,453 ERROR [STDERR] at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
22:56:16,453 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
22:56:16,453 ERROR [STDERR] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
22:56:16,453 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
22:56:16,453 ERROR [STDERR] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
22:56:16,453 ERROR [STDERR] at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
22:56:16,453 ERROR [STDERR] at java.lang.Thread.run(Thread.java:662)



...全文
94 点赞 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
问题解决,<jndi-name>Advice</jndi-name>这问题改为<jndi-local-name>Advice</jndi-local-name>
回复
不行啊,试过了,能不能有别的方法。。。
回复
daiyuezai 2012-06-02
jboss 需要 使用 ctx.lookup("java:Advice");\
tomcat 也不同。
回复
相关推荐
发帖
Java EE
创建于2007-09-28

6.6w+

社区成员

J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
申请成为版主
帖子事件
创建了帖子
2012-06-02 10:57
社区公告
暂无公告