2
回答
initialContext.lookup()抛出异常
利用AWS快速构建适用于生产的无服务器应用程序,免费试用12个月>>>   

   1. initialContext = new InitialContext();  
   2. Object objref = initialContext.lookup("security-sample/UserManagement");  

这个对looup方法的引用抛出异常:

   1. javax.servlet.ServletException: UserManagement not bound  
   2.     at servlet.SampleServlet.initBean(SampleServlet.java:99)  
   3.     at servlet.SampleServlet.doGet(SampleServlet.java:36)  
   4.     at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)  
   5.     at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)  

我想问,lookup的这个参数"security-sample/UserManagement"在哪里定义呢?
我的工程里几个配置文件如下:
jboss.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 3.0//EN" "http://www.jboss.org/j2ee/dtd/jboss_3_0.dtd">
<jboss>
	<security-domain>java:/jaas/sample_web_client_security</security-domain>
	<enterprise-beans>
		<session>
			<ejb-name>UserManagement</ejb-name>
			<jndi-name>security-sample/UserManagement</jndi-name>
		</session>
	</enterprise-beans>
	<resource-managers/>
</jboss>

jboss-web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<jboss-web>
	<context-root>security-sample</context-root>
	<security-domain>java:/jaas/sample_web_client_security</security-domain>
</jboss-web>

ejb-jar.xml部分session-bean的定义如下:

		<!-- Session Beans -->
		<session>
			<description><![CDATA[Session Bean for UserManagement]]></description>
			<ejb-name>UserManagement</ejb-name>
			<home>com.sample.ejb.UserManagementHome</home>
			<remote>com.sample.ejb.UserManagement</remote>
			<ejb-class>com.sample.ejb.UserManagementBean</ejb-class>
			<session-type>Stateless</session-type>
			<transaction-type>Container</transaction-type>
			<security-role-ref>
				<role-name>Member_admin</role-name>
				<role-link>Member_admin</role-link>
			</security-role-ref>
		</session>
	</enterprise-beans>

 

com.sample.ejb.UserManagementHome.java

package com.sample.ejb;

/**
 * Home interface for UserManagement.
 */
public interface UserManagementHome
   extends javax.ejb.EJBHome
{
   public static final String COMP_NAME="java:comp/env/ejb/UserManagement";
   public static final String JNDI_NAME="security-sample/UserManagement";

   public UserManagement create()
      throws javax.ejb.CreateException,java.rmi.RemoteException;

}
举报
lingxue
发帖于7年前 2回/720阅
顶部