提示信息:
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
原因是,在hibernate.cfg.xml中对<session-factory name=“foo”>标签指定了name属性!
name="xxxx" 是为了把SessionFactory的唯一实例bind到jndi上的,这样可以通过new InitialContext().lookup("xxxx")来得到SessionFactory,不过实际上没什么用处。
非j2ee容器下直接执行或容器不支持jndi动态bind(如tomcat)都会出现这个问题。