EJB3.0异常总结--- Need to specify class name in environment or system property,

版权声明:本文为博主原创文章,未经博主credreamer 允许不得转载 违者追究法律责任。 https://blog.csdn.net/lidew521/article/details/8470664
异常:
 Need to specify class name in environment or system property, or    


as an applet parameter, or in an application resource file:     


java.naming.factory.initial
  原因:
  1.没有写入jndi.properties.
  2.Need to specify class name in environment or system property. 的 
   意思就是找不到你的EJB环境变量. 换句话说就是你的客户在使用lookup   
   的时候. context没有设置对.
  3.Need to specify class name in environment or system property, or 
    as an applet parameter, or in an application resource file:      
    java.naming.factory.initial
     使用的是代码InitialContext     
     ctx=new InitialContext(props);的方式,不存在jndi配置文件不对的问 
    题,最后想起之前一个教程里的一句命名空间的话,于是登录jboss控制  
    台,找到部署的ejb,前面一个java提醒鸟我,将代码里lookup中参数前  
    面加上java:,搞定。
  
 public class EjbClient {  
    public static void main(String[] args) {  
        Properties props=new Properties();  
        props.setProperty


("java.naming.factroy.initial","org.jnp.interfaces.NamingContextFact


ory");  
        props.setProperty


("java.naming.provider.url","localhost:1099");//或者


jnp://localhost...也可  
        props.setProperty("java.naming.factory.url.pkgs", 


"org.jboss.naming:org.jnp.interfaces");//此行必须有  
        try{  
            InitialContext ctx=new InitialContext(props);  
            HelloWorld helloworld=(HelloWorld)ctx.lookup


("java:HelloWorldBean/remote");//前面的java是关键  
            System.out.println(helloworld.sayHello("jack"));  
        }catch(NamingException e){  
            System.out.println("error:"+e.getMessage());  
        }  
    }  
}  

编译MonitorDown出错 Need to specify class name in environment or system property,

08-27

public class DBconnectrnrnrn public DBconnect()rn rn debug = true;rn con = null;rn stmt = null;rn rs = null;rn resultsMeta = null;rn rows = 0;rn columns = 0;rn PoolName = "jdbc/song";rn initUsePool();rn rnrn public void initUsePool()rn rn tryrn rn InitialContext initialcontext = new InitialContext();rn Context context = (Context)initialcontext.lookup("java:comp/env");rn DataSource datasource = (DataSource)context.lookup(PoolName);rn con = datasource.getConnection();rn rn catch(NamingException namingexception)rn rn System.out.println("Connection pool fail. Message is:");rn System.out.println(namingexception.getMessage());rn rn catch(SQLException sqlexception)rn rn System.out.println("SQL Exception occur. Message is:");rn System.out.println(sqlexception.getMessage());rn rn rnrn public Connection getCon()rn rn return con;rn rnrnrnpublic class MonitorDown rnrnpublic MonitorDown()rnrnpublic static void main(String args[])rn rn DBconnect conn=null;rn conn= new DBconnect();rn Connection connect=conn.getCon();rn PreparedStatement stmt=null;rn PreparedStatement stmt2=null;rn ResultSet rs =null;rn String sql ="";rn int OrderId=0;rn Date currentTime = new Date();rn long NowDate=(currentTime.getTime()/1000)-60*30;rn long TimeoutDate=(currentTime.getTime()/1000)-60*60*3;rn long Time=0;rn Date setTime = null;rn tryrn sql="select OL_ID,OL_RegTime from tbl_orderlist where OL_Download=2"; rn stmt=conn.prepareStatement(sql);rn rs =conn.executePreQuery();rn rn if(rs != null)rn rs.close(); rn if(stmt!=null)rn stmt.close();rn if(stmt2!=null)rn stmt2.close();rn if(connect != null)rn connect.close(); rn rn catch (SQLException e) rn System.out.println("SQL Exception occur. Message is:");rn System.out.println(e.getMessage());rn rn conn.close(); rnrnrnrnrn编译MonitorDown出错rnConnection pool fail. Message is:rn Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initialrn

第一个EJB 异常Need to specify class name in environment。。。

08-02

我在myeclipse里写EJB3,用的是jboss4.0.5rn建了一个服务器端的EJB工程,写了个接口,一个实现类,实现类里写了@Stateless @Remotern又建了个客户端的JAVA工程,把服务器端的接口打了个JAR包,添加到客户端里去了。JBOSS的LIB里的JAR包也全拷进去了。rn还写了个jndi.propertiesrnjava.naming.factory.initial=org.jnp.interfaces.NamingContextFactoryrnjava.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfacesrnjava.naming.provider.url=localhostrn启动JBOSS没问题,我也部署了,但是启动时控制台上却没有输出部署文件的信息,只有输出JBOSS启动的一些基本信息,我在JBOSS目录里也看了,是有ebj01.jar这个文件夹的,里面也有接口和实现类的class文件。rn现在在客户端调用的时候出现问题rnException in thread "main" javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initialrn at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)rn at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)rn at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)rn at javax.naming.InitialContext.lookup(InitialContext.java:392)rn at com.accp.ejb.FirstEjbClient.main(FirstEjbClient.java:9)rn好像是找不到实现类吧。这是为什么呢

lookup时遇到一个问题:NoInitialContextException: Need to specify class name in environment or system property怎么办?

03-07

报错:rnjavax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initialrn at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:640)rn at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)rn at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:280)rn at javax.naming.InitialContext.lookup(InitialContext.java:347)rn at org.qhy.exam.test.main(test.java:18)rnrn原码:(test.java)rnpackage org.qhy.exam;rnrnimport java.sql.Connection;rnimport java.sql.SQLException;rnimport java.sql.Statement;rnimport java.sql.ResultSet;rnrnimport javax.naming.InitialContext;rnimport javax.naming.NamingException;rnimport javax.sql.DataSource;rnrnpublic class test rn public static void main(String[] args)rn try rn InitialContext initCtx = new InitialContext();rn DataSource source =rn (DataSource)initCtx.lookup("java:comp/env/jdbc/test");rn Connection conn = source.getConnection();rn Statement s = conn.createStatement();rnrn ResultSet rs = s.executeQuery("select * from user");rnrn while(rs.next()) rn System.out.println("您的第一个字段内容为:" rn + rs.getString(1));rn System.out.println("您的第一个字段内容为:" rn + rs.getString(2));rn rn catch (NamingException ne) rn ne.printStackTrace();rn catch (SQLException se) rn se.printStackTrace();rn rn rn

Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: ja

10-24

请问各位大侠,Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initialrncom.datang.exception.ApplicationException是什么原因呢?烦请高手指导指导。一下是出错的代码:rnpackage com.datang.dao.impl;rnrnimport java.sql.Connection;rnimport java.sql.PreparedStatement;rnimport java.sql.ResultSet;rnimport java.sql.SQLException;rnimport java.util.ArrayList;rnimport java.util.List;rnrnimport com.datang.dao.EmployeeDAO;rnimport com.datang.exception.ApplicationException;rnimport com.datang.po.Employee;rnimport com.datang.po.EmployeeList;rnimport com.datang.util.DBUtil;rnrnpublic class EmployeeMySQLDAOImpl implements EmployeeDAOrn rn public static final String GET_EMPLOYEE_BY_ID="select id,name,sex,hire_date,position,birthday,degree,major,experience rnrnfrom t_employee";rn rnrn public EmployeeList getEmployeeById(String id)throws ApplicationExceptionrn Connection conn=null;rn PreparedStatement pstmt=null;rn ResultSet rs=null;rn EmployeeList emp=new EmployeeList();rn rn tryrn conn=DBUtil.getConnection(); <-----从这一句就直接跳转的finally里边了。。rn pstmt=conn.prepareStatement(GET_EMPLOYEE_BY_ID);rn pstmt.setString(1, id);rn rs=pstmt.executeQuery();rn while(rs.next())rn rn emp.setId(rs.getString(1));rn emp.setName(rs.getString(2));rn emp.setSex(rs.getString(3).equals("0")?"男":"女");rn emp.setHire_date(rs.getDate(4));rn emp.setPosition(rs.getString(5));rn emp.setBirthday(rs.getDate(6));rn emp.setDegree(rs.getString(7));rn emp.setMajor(rs.getString(8));rn emp.setExperience(rs.getString(9));rn rn return emp;rn catch(SQLException e)rn e.printStackTrace();rn return null;rn finallyrn DBUtil.close(rs, pstmt, conn);rn rn rn rn public static void main(String[] args)rn try rn EmployeeList name=new EmployeeMySQLDAOImpl().getEmployeeById("1");rn System.out.println(name);rn catch (ApplicationException e) rn // TODO Auto-generated catch blockrn e.printStackTrace();rn rn rnrnrn抛出的异常是:2008-10-24 09:42:45:INFO main com.datang.util.DBUtil - 数据库发生异常Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initialrncom.datang.exception.ApplicationExceptionrn at com.datang.util.DBUtil.getConnection(DBUtil.java:32)rn at com.datang.dao.impl.EmployeeMySQLDAOImpl.getEmployeeById(EmployeeMySQLDAOImpl.java:166)rn at com.datang.dao.impl.EmployeeMySQLDAOImpl.main(EmployeeMySQLDAOImpl.java:193)rnrn经检查DBUtil.java ApplicationException.java 都没错,谢谢了!!rn

tomcat 数据源问题:Need to specify class name in environment

05-01

javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initialrn at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)rn at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)rn at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)rn at javax.naming.InitialContext.lookup(InitialContext.java:392)rn at DBpool.createConn(DBpool.java:18)rn at DBpool.main(DBpool.java:36)rnrn在META-INF下面配置context.xml , 用户名密码都没错,url,driverClassName也没错。我测试过了。rn[code=XML]rnrnrn rnrn[/code]rnrn连接池类rn[code=Java]rnimport java.sql.Connection;rnimport java.sql.SQLException;rnrnimport javax.naming.Context;rnimport javax.naming.InitialContext;rnimport javax.naming.NamingException;rnimport javax.sql.DataSource;rnrnpublic class DBpoolrnrn private Connection conn;rnrn public void createConn()rn rn tryrn rn Context initCtx = new InitialContext();// initalize Context Object.rn DataSource ds = (DataSource) initCtx.lookup("java:comp/env/jdbc/DBpool");rn rn conn = ds.getConnection();rn System.out.println(conn==null);rn catch (NamingException e)rn rn // TODO Auto-generated catch blockrn e.printStackTrace();rn catch (SQLException e)rn rn // TODO Auto-generated catch blockrn e.printStackTrace();rn rn rn rn public static void main(String[] args)rn rn DBpool conndbpool= new DBpool();rn conndbpool.createConn();rn rnrnrnrn[/code]rnrn

连接池问题 Need to specify class name in envir

05-04

rnrnrnrnnewsrnjavax.sql.DataSourcernContainerrnrn运行:rn public static void main(String[] args)rnrn try rn Context ctx = new InitialContext(); rn rn Context envContext = (Context)ctx.lookup("java:/comp/env"); rn DataSource ds = (DataSource)envContext.lookup("news"); rn rn Connection conn = ds.getConnection(); rn conn.close(); rn System.out.print("连接成功");rn catch (NamingException e) rn // TODO Auto-generated catch blockrn e.printStackTrace();rn catch (SQLException e) rn // TODO Auto-generated catch blockrn e.printStackTrace();rn rn rn报错:rnjavax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initialrn at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)rn at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)rn at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)rn at javax.naming.InitialContext.lookup(InitialContext.java:392)rn at dao.ForumDao.main(ForumDao.java:33)用实例类进行测试时候遇到了上述问题,用Servlet或jsp页面却是成功的,没有错误。为什马呢?rnrn浏览器访问test.jsp没问题,显示连接成功!rntest.jsp:rn<%@ page language="java" import="javax.naming.*,javax.sql.*,java.sql.*" pageEncoding="GBK"%>rn<%rn Context ctx = new InitialContext();rn DataSource ds = (DataSource) ctx.lookup("java:comp/env/news");rn Connection con = ds.getConnection();rn out.print("连接成功");rn rn%>rnrn

javax.naming.NoInitialContextException: Need to specify class name in environmen

11-23

我的JAVA代码如下:rnimport java.sql.SQLException;rnimport java.sql.Statement;rnimport java.sql.Connection;rnimport java.sql.ResultSet;rnrnimport javax.naming.Context;rnimport javax.naming.InitialContext;rnimport javax.naming.NamingException;rnimport javax.sql.DataSource;rnrnpublic class DataPage rnrn public static Connection getConnection() rn Connection con = null;rn try rn Context initContext = new InitialContext();rn Context envContext = (Context) initContext.lookup("java:comp/env");rn DataSource ds= (DataSource) envContext.lookup("jdbc/sample_db");rn if (ds != null) rn System.out.println("找到数据源");rn con = ds.getConnection();rn return con;rn rn catch (Exception e) rn // TODO Auto-generated catch blockrn e.printStackTrace();rn rn return null;rnrn rnrn public ResultSet getData(String sql) rn Connection conn;rn ResultSet rs = null;rn try rn conn = DataPage.getConnection();rn Statement st = conn.createStatement(rn ResultSet.TYPE_SCROLL_INSENSITIVE,rn ResultSet.CONCUR_READ_ONLY);rn return st.executeQuery(sql);rn catch (SQLException e) rn // TODO Auto-generated catch blockrn e.printStackTrace();rn rn return null;rn rnrn public static void main(String[] args) rn String sql = "select * from PRODUCTSMANAGER";rn ResultSet rst = new DataPage().getData(sql);rn try rn while (rst.next()) rn rst.last();rn int rowCount = rst.getRow();rn int pageSize = 5;rn int pageCount = (rowCount + pageSize - 1) / pageSize;rn for (int i = 1; i <= pageCount; i++) rn rst.absolute((i - 1) * pageSize + 1);rn for (int j = 0; j < ((i - 2) * pageSize + 1); j++) rn String a = rst.getString("ProductName");rn System.out.println(a);rn rnrn rn rn catch (SQLException e) rn // TODO Auto-generated catch blockrn e.printStackTrace();rn rn rnrn老报以下错误,请各位帮忙处理下,谢谢:rnjavax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initialrn at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)rn at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)rn at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)rn at javax.naming.InitialContext.lookup(InitialContext.java:392)rn at com.test.DataPage.getConnection(DataPage.java:19)rn at com.test.DataPage.getData(DataPage.java:38)rn at com.test.DataPage.main(DataPage.java:52)rnException in thread "main" java.lang.NullPointerExceptionrn at com.test.DataPage.getData(DataPage.java:39)rn at com.test.DataPage.main(DataPage.java:52)rn

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试

关闭